JmeSystem.getStorageFolder() not working for Android

getStorageFolder does not seem to work on Android.



[java]storageFolder = new File(System.getProperty("user.home"), ".jme3");[/java]



returns an invalid storage location on Android. Can the Android specific getStorageLocation be added to JmeAndroidSystem.java so that the same JmeSystem.getStorageLocation() call will work on both the PC and Android systems? Something like the following seems to work:



[java]

This patch file was generated by NetBeans IDE

Following Index: paths are relative to: D:UserspotterecDocumentsjMonkeyProjects_NightlyjME3srcandroidcomjme3systemandroid

This patch can be applied using context Tools: Patch action on respective folder.

It uses platform neutral UTF-8 encoding and n newlines.

Above lines and this line are ignored by the patching process.

Index: JmeAndroidSystem.java

— JmeAndroidSystem.java Base (BASE)

+++ JmeAndroidSystem.java Locally Modified (Based On LOCAL)

@@ -2,6 +2,7 @@



import android.app.Activity;

import android.content.res.Resources;

+import android.os.Environment;

import com.jme3.asset.AndroidAssetManager;

import com.jme3.asset.AssetManager;

import com.jme3.audio.AudioRenderer;

@@ -13,6 +14,7 @@

import com.jme3.system.Platform;

import com.jme3.util.AndroidLogHandler;

import com.jme3.util.JmeFormatter;

+import java.io.File;

import java.net.URL;

import java.util.logging.Handler;

import java.util.logging.Level;

@@ -101,4 +103,33 @@

public static Activity getActivity() {

return activity;

}

+

  • @Override
  • public synchronized File getStorageFolder() {
  •    //http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir<br />
    
  •    //http://developer.android.com/guide/topics/data/data-storage.html<br />
    

+

  •    boolean mExternalStorageWriteable = false;<br />
    
  •    String state = Environment.getExternalStorageState();<br />
    
  •    if (Environment.MEDIA_MOUNTED.equals(state)) {<br />
    
  •        mExternalStorageWriteable = true;<br />
    
  •    } else {<br />
    
  •        mExternalStorageWriteable = false;<br />
    

}

+

  •    if (mExternalStorageWriteable) {<br />
    
  •        //getExternalFilesDir automatically creates the directory if necessary.<br />
    
  •        //directory structure should be: /mnt/sdcard/Android/data/&lt;packagename&gt;/files<br />
    
  •        //when created this way, the directory is automatically removed by the Android<br />
    
  •        //  system when the app is uninstalled<br />
    
  •        storageFolder = activity.getApplicationContext().getExternalFilesDir(null);<br />
    
  •        logger.log(Level.INFO, &quot;Storage Folder Path: {0}&quot;, storageFolder.getAbsolutePath());<br />
    

+

  •        return storageFolder;<br />
    
  •    } else {<br />
    
  •        return null;<br />
    
  •    }<br />
    

+

  • }

    +

    +}



    [/java]
1 Like

Thanks, thats helpful.