Here is my code to check for the availability of the application on the SD card:
public static boolean isInstalledOnSdCard() {
Context context = App.getContext();
if (VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
ApplicationInfo ai = pi.applicationInfo;
return (ai.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE;
} catch (NameNotFoundException e) {
}
}
try {
String filesDir = context.getFilesDir().getAbsolutePath();
if (filesDir.startsWith("/data/")) {
return false;
} else if (filesDir.contains("/mnt/") || filesDir.contains("/sdcard/")) {
return true;
}
} catch (Throwable e) {
}
return false;
}
source
share