Use Environment.getExternalStorageDirectory()

Use this instead of directly referencing “/sdcard.” This is necessary
for newer Android devices, particularly those which support multiple
“users” of the device.

Change-Id: Ic8603865a3927aafeaacf82b00e985506a326b60
parent ee2c760a
......@@ -18,6 +18,7 @@ import com.google.appinventor.components.runtime.util.RetValManager;
import dalvik.system.DexClassLoader;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
......@@ -35,8 +36,10 @@ public class ReplForm extends Form {
private AppInvHTTPD httpdServer = null;
public static ReplForm topform;
private static final String REPL_ASSET_DIR = "/sdcard/AppInventor/assets/";
private static final String REPL_COMP_DIR = "/sdcard/AppInventor/assets/external_comps/";
private static final String REPL_ASSET_DIR =
Environment.getExternalStorageDirectory().getAbsolutePath() +
"/AppInventor/assets/";
private static final String REPL_COMP_DIR = REPL_ASSET_DIR + "external_comps/";
private boolean IsUSBRepl = false;
private boolean assetsLoaded = false;
private boolean isDirect = false; // True for USB and emulator (AI2)
......
......@@ -50,7 +50,7 @@ public class MediaUtil {
private enum MediaSource { ASSET, REPL_ASSET, SDCARD, FILE_URL, URL, CONTENT_URI, CONTACT_URI }
private static final String LOG_TAG = "MediaUtil";
private static final String REPL_ASSET_DIR = "/sdcard/AppInventor/assets/";
private static String REPL_ASSET_DIR = null;
// tempFileMap maps cached media (assets, etc) to their respective temp files.
private static final Map<String, File> tempFileMap = new HashMap<String, File>();
......@@ -97,6 +97,15 @@ public class MediaUtil {
}
private static String replAssetPath(String assetName) {
// We have to initialize this here. We used to set REPL_ASSET_DIR
// in the initializer, but now that we fetch it from the Android
// SDK we have to do this here otherwise we get a "Stub!" error
// under the unit tests (which do not run on a device or emulator,
// so only has access to the android "stub" libraries.)
if (REPL_ASSET_DIR == null) { // Fetch it the first time
REPL_ASSET_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/AppInventor/assets/";
}
return REPL_ASSET_DIR + assetName;
}
......
......@@ -11,6 +11,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import java.io.BufferedInputStream;
......@@ -29,7 +30,9 @@ import com.google.appinventor.components.runtime.Form;
public class PackageInstaller {
private static final String LOG_TAG = "PackageInstaller(AppInventor)";
private static final String REPL_ASSET_DIR = "/sdcard/AppInventor/assets/";
private static final String REPL_ASSET_DIR =
Environment.getExternalStorageDirectory().getAbsolutePath() +
"/AppInventor/assets/";
// We don't instantiate this, we just have static methods
private PackageInstaller() {
......@@ -66,4 +69,4 @@ public class PackageInstaller {
}
});
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment