Aquí está mi código para comprobar si la aplicación está instalada en la tarjeta SD:
/**
* Checks if the application is installed on the SD card.
*
* @return <code>true</code> if the application is installed on the sd card
*/
public static boolean isInstalledOnSdCard() {
Context context = App.getContext();
// check for API level 8 and higher
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) {
// ignore
}
}
// check for API level 7 - check files dir
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) {
// ignore
}
return false;
}
interesante. Considero que el nivel de API 7 es para teléfonos rooteados. Y las importaciones faltan. – Martin