Is there a way to detect whether the apk is stored on SD-card or not? How?
Use getApplicationInfo().sourceDir
http://developer.android.com/reference/android/content/pm/ApplicationInfo.html
To make the accepted answer more concrete, here's an example of how I've used it in the context of accessing files written to internal vs external storage, according to API level 7 guidelines or lower:
{ //...
mInternalApp = context.getApplicationInfo().sourceDir.matches("^/data/app/.*");
mPathInternal = context.getApplicationInfo().dataDir + "/files/";
mPathExternal = Environment.getExternalStorageDirectory() + "/Android/data/"
+ PACKAGE_NAME + "/files/";
}
private File getMyFile() {
return (mInternalApp) ? new File(mPathInternal + INT_FILE_NAME) :
new File(mPathExternal + EXT_FILE_NAME);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With