Android 2.2中的APK安装参数installLocation

在Android 2.2中新的特性可以支持类似APP2SD卡上,我们的APK文件可以安装在SD卡上供用户使用,Android123今天就说下目前项目的升级和一些配置。
  1. 首先让你的程序支持SD卡上安装必须具备设置API Level至少为8,即androidmanifest.xml的中android:minSdkVersion至少为8这样你的APK最终运行时兼容的固件只有2.2了,同时在androidmanifest.xml文件的根节点中必须加入android:installLocation这个属性,类似代码如下:
  < manifest xmlns:andro
  android:installLocation="preferExternal"
  ... >
  复制代码
  2. android:installLocation的值主要有preferExternal、auto 和internalOnly这三个选项,通常我们设置为preferExternal可以优先推荐应用安装到SD卡上,当然最终用户可以选择为内部的 ROM存储上,如果外部存储已满,Android内部也会安装到内部存储上,auto将会根据存储空间自适应,当然还有一些应用可能会有特殊的目的,他们一般必须安装在内部存储才能可靠运行,设置为internalOnly比较合适,主要体现在:
  Services 服务
  Your running Service will be  kill ed and will not be restarted when external storage is remounted. You can, however, register for the ACTION_EXTERNAL_APPLICATIONS_AVAILABLE broadcast Intent, which will notify your application when applications installed on external storage have become available to the system again. At which time, you can restart your Service. Android123提示大家一般实时后台监控类的应用都应该装到内部存储,比较可靠。
  Alarm Services 闹铃提醒服务
  Your alarms registered with AlarmManager will be cancelled. You must manually re-register any alarms when external storage is remounted.
  Input Method Engines 输入法引擎
  Your IME will be replaced by the default IME. When external storage is remounted, the user can open system settings to enable your IME again.
  Live Wallpapers 活动壁纸
  Your running Live Wallpaper will be replaced by the default Live Wallpaper. When external storage is remounted, the user can select your Live Wallpaper 
〖黑软手机 资讯频道〗
  
again. 
  Live Folders 活动文件夹
  Your Live Folder will be removed from the home screen. When external storage is remounted, the user can add your Live Folder to the home screen again.
  App Widgets Widget
  Your App Widget will be removed from the home screen. When external storage is remounted, your App Widget will not be available for the user to select until the system resets the home application (usually not until a system reboot).
  Account Managers 账户管理
  Your accounts created with AccountManager will disappear until external storage is remounted.
  Sync Adapters 同步适配器
  Your AbstractThreadedSyncAdapter and all  it s sync functionality will not work until external storage is remounted.
  Device Administrators 设备管理器
  Your DeviceAdminReceiver and all  it s admin capabilities will be disabled, which can have unforeseeable consequences for the device functionality, which may persist after external storage is remounted.
  那么哪些应用适合安装在SD卡中呢? Android开发网建议一些占用资源比较大的游戏,比如大于3MB的单个文件,不需要长期驻留内存的应用,不具备提醒和实时监控的应用一般放到SD卡上比较合适,不过目前想让你的应用装到SD卡上,必须设置API Level至少为8以上,同时显示注明android:installLocation。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 代码使用 pm 命令安装 APK 的方法如下: 1. 在 Android 设备上启用开发者选项。您可以在设备设置找到此选项,并启用它。 2. 在 Android 代码,使用以下命令执行 pm 命令: ```java Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); os.writeBytes("pm install /path/to/apk/file.apk\n"); os.flush(); ``` 其,`/path/to/apk/file.apk` 是您要安装APK 文件的路径。请注意,您需要将此路径替换为实际的 APK 文件路径。 如果您不知道 APK 文件的路径,可以使用以下命令列出设备上所有已安装的应用程序的包名: ```java Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); os.writeBytes("pm list packages\n"); os.flush(); ``` 这将返回一个包含所有已安装应用程序的包名列表。您可以在列表找到您要安装的应用程序的包名,并使用以下命令卸载它: ```java Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); os.writeBytes("pm uninstall package_name\n"); os.flush(); ``` 其,`package_name` 是应用程序的包名,可以在 AndroidManifest.xml 文件找到。 请注意,在使用 pm 命令安装或卸载应用程序之前,请确保您已经连接了 Android 设备并启用了 USB 调试选项。您可以在设备设置找到此选项,并启用它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值