這裏是我的,如果安裝在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;
}
有趣。我認爲API級別7適用於固定電話。而進口缺失。 – Martin 2011-06-22 07:34:21