Android应用程序的默认安装位置以及是否可移动取决于开发者在其AndroidManifest.xml中的设置

<manifest xmlns:android = "http://schemas.android.com/apk/res/android" android:versionCode = "1" android:installLocation = "auto" android:versionName = "1.0" >

android:installLocation的值有三个 internalOnly , auto , preferExternal ,缺省值为internalOnly internalOnly 表示该应用程序只能安装到手机内部存储中。 auto 表示由系统决定该应用程序安装到手机内部存储中还是SD卡中。 如果有SD卡且应用程序大于5M的话,安装到SD卡中,否则安排到手机内部存储中 preferExternal 表示如果有SD卡就把该应用程序只能安装到SD卡中,否则安装到手机内部存储中。 android:installLocation internalOnly 时,用户在"Setting"->"Application"->"Manage applications"中不能把应用程序在SD卡与内存中相互移动 android:installLocation auto preferExternal 时,用户在"Setting"->"Application"->"Manage applications"中可以把应用程序在SD卡与内存中相互移动 另外,adb shell 中可以使用 pm setInstallLocation 2 命令中强行更改安装位置。 2 代表的是强制安装在SD卡中, 0 代表自动, 1 代表强制装到 手机内部存储中。 在代码中,对于高于 Android 2.2 的手机中, 可以通过 ApplicationInfo.FLAG_EXTERNAL_STORAGE 标记可以判断应用是否安装在Sdcard上,对于低于Android 2.2的手机可以通过ApplicationInfo的sourceDir属性为/sdcard/开头来确定APK安装的位置。 示例1

PackageManager pm = ctx . getPackageManager (); ApplicationInfo appInfo = pm . getApplicationInfo ( pkgName , 0 ); if (( appInfo . flags & ApplicationInfo . FLAG_EXTERNAL_STORAGE ) != 0 ) { // App on sdcard System.out.println(pkgName+" install on sdcard");

结束!

更多相关文章

  1. 【OSC手机App技术解析】- Android完全退出程序
  2. Android之NDK开发
  3. Android(安卓)- Android应用程序(Application)的主要组件
  4. Android开发手记--环境配置
  5. 用Eclipse开发和调试Android应用程序(一)
  6. android层次结构
  7. 【Android开发】Android入门安装与使用教程——以Android(安卓)S
  8. App for Android(安卓)(2) —— Python篇
  9. Android(安卓)- Android应用程序(Application)的主要组件

随机推荐

  1. Hello Android(安卓)- android窗体透明的
  2. android api 中文 (74)—— AdapterView.Ad
  3. Android(安卓)EditText 设置行距不影响光
  4. MTK Android(安卓)Driver:led
  5. Android(安卓)Calendar使用过程中遇到的
  6. Android,LIstView中的OnItemClick点击无
  7. Android(安卓)--- BaseAdapter
  8. Android(安卓)UI开发第十七篇——Android
  9. Android(安卓)N 指纹框架
  10. Android(安卓)UI系列 - 布局 - 目录