App Install Location android应用程序安装位置详解



    从API8开始,你可以允许你的应用程序安装在外部存储中,(比如设备的SD卡中)。这是一个可选的特征,你可以为你的应用程序声明此特征,在mianfest属性中,用android:installLocation标签声明。如果你没有声明此属性,你的应用程序将默认安装到手机内部存储中,并且将不能移动到外部存储。


为了允许系统将你的程序安装到外部存储中,你要修改你的mainfest文件,使其在<mainfest>元素标签中包含android:installLocation属性,其值可以为“preferExternal”或者“auto”或者“internalOnly”. For example:
 <mainfest xmls:android="http://schemas.android.com/apk/res/android"
            android:installLocation="preferExternal"
          .....>
如果你声明了“preferExternal”,你会请求你的应用程序安装在外部存储中,但是系统不好保证你的应用程序就会安装在外部存储中。如果外部存储满了,系统就会将程序安装到内部存储之中。用户可以在两者之间移动应用程序的位置。

如果你声明“auto”,表名你的应用程序可能会安装到外部存储中,但对安装位置没有特别偏好。系统基于很多因素决定安装你程序的位置。用户也可以在两者之间移动应用程序的位置。
  
    当你的程序被安装到外部存储的时候:
  • 不影响应用程序的性能,只要你的外部存储安装在设备上。
  • .apk文件保存于外部存储中,但是所有私人的用户数据,数据库,优化过的.dex文件,和提取的原生代码将会保存到设备内存当中。
  • 你应用程序安装的独特的容器是被一个随机生成加密的钥匙加密过,只能够被原始安装此应用程序设备的私钥解密。因此,一个应用程序安装在一张sd卡只为一台设备工作。
  • 用户能够通过系统设置移动你应用程序到内部存储中。


Backward Compatibility 向后兼容
允许你的应用程序安装到外存上是android2.2 或者更高级别版本的特征,在api8 之前开发的程序往往安装在内存中并且不能移动到外存中(即使在支持api8的设备上)。然后,如果你的程序是用低于api8设计的,你可以选择支持这项功能的api8的设备或者更高版本的,
并且至今仍是一个API兼容设备支持低于api8的。

为了允许安装到外部存储,并且兼容低于api8版本:
1.在<mainfest>元素中,设置android:installLocation,值可以为”auto“ or"preferExternal"
2.设置android:miniSdkVersion属性值 低于8.确保你的应用程序的代码只使用兼容那个版本的api。
3.为了编译你的应用程序,改变你 的build target为API8,这是必须的,因为老版本的android 类库不能够 解析android:installLocation 这个属性,这样就不能编译你现有的应用程序。

当你的设备是低于android2.2的,那个标签会被忽略,应用程序会安装到内存中。


Applications that should not install on external storage
应用程序不应该安装到外部存储的情况

当手机通过usb连接电脑分享文件的时候(或者移除SD卡的时候),安装在外存上正在运行的程序会被kill掉。
(以下简单就不翻译了)
Services 服务
Your running  Service will be killed 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.
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 小工具
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 its sync functionality will not work until external storage is remounted.
Device Administrators 设备管理员
Your  DeviceAdminReceiver and all its admin capabilities will be disabled, which can have unforeseeable consequences for the device functionality, which may persist after external storage is remounted.
Broadcast Receivers listening for "boot completed"   广播监听 引导完成
The system delivers the  ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast.
Copy Protection 拷贝保护
Your application cannot be installed to a device's SD card if it uses Android Market's Copy Protection feature. However, if you use Android Market's  Application Licensing instead, your application  can be installed to internal or external storage, including SD cards

If your application uses any of the features listed above, you should not allow your application to install on external storage. By default, the system will not allow your application to install on the external storage, so you don't need to worry about your existing applications. However, if you're certain that your application should never be installed on the external storage, then you should make this clear by declaring android:installLocation with a value of "internalOnly". Though this does not change the default behavior, it explicitly states that your application should only be installed on the internal storage and serves as a reminder to you and other developers that this decision has been made.


 
 
 
 
应用程序应该安装到外部存储的情况:
 
 
就是除了上述列出不能安装在外存的情况,安装到外存都是允许的了。特别是占用大量空间的游戏等。

In simple terms, anything that does not use the features listed in the previous section are safe when installed on external storage. Large games are more commonly the types of applications that should allow installation on external storage, because games don't typically provide additional services when inactive. When external storage becomes unavailable and a game process is killed, there should be no visible effect when the storage becomes available again and the user restarts the game (assuming that the game properly saved its state during the normal Activity lifecycle).

If your application requires several megabytes for the APK file, you should carefully consider whether to enable the application to install on the external storage so that users can preserve space on their internal storage.

    从API8开始,你可以允许你的应用程序安装在外部存储中,(比如设备的SD卡中)。这是一个可选的特征,你可以为你的应用程序声明此特征,在mianfest属性中,用android:installLocation标签声明。如果你没有声明此属性,你的应用程序将默认安装到手机内部存储中,并且将不能移动到外部存储。


为了允许系统将你的程序安装到外部存储中,你要修改你的mainfest文件,使其在<mainfest>元素标签中包含android:installLocation属性,其值可以为“preferExternal”或者“auto”或者“internalOnly”. For example:
 <mainfest xmls:android="http://schemas.android.com/apk/res/android"
            android:installLocation="preferExternal"
          .....>
如果你声明了“preferExternal”,你会请求你的应用程序安装在外部存储中,但是系统不好保证你的应用程序就会安装在外部存储中。如果外部存储满了,系统就会将程序安装到内部存储之中。用户可以在两者之间移动应用程序的位置。

如果你声明“auto”,表名你的应用程序可能会安装到外部存储中,但对安装位置没有特别偏好。系统基于很多因素决定安装你程序的位置。用户也可以在两者之间移动应用程序的位置。
  
    当你的程序被安装到外部存储的时候:
  • 不影响应用程序的性能,只要你的外部存储安装在设备上。
  • .apk文件保存于外部存储中,但是所有私人的用户数据,数据库,优化过的.dex文件,和提取的原生代码将会保存到设备内存当中。
  • 你应用程序安装的独特的容器是被一个随机生成加密的钥匙加密过,只能够被原始安装此应用程序设备的私钥解密。因此,一个应用程序安装在一张sd卡只为一台设备工作。
  • 用户能够通过系统设置移动你应用程序到内部存储中。


Backward Compatibility 向后兼容
允许你的应用程序安装到外存上是android2.2 或者更高级别版本的特征,在api8 之前开发的程序往往安装在内存中并且不能移动到外存中(即使在支持api8的设备上)。然后,如果你的程序是用低于api8设计的,你可以选择支持这项功能的api8的设备或者更高版本的,
并且至今仍是一个API兼容设备支持低于api8的。

为了允许安装到外部存储,并且兼容低于api8版本:
1.在<mainfest>元素中,设置android:installLocation,值可以为”auto“ or"preferExternal"
2.设置android:miniSdkVersion属性值 低于8.确保你的应用程序的代码只使用兼容那个版本的api。
3.为了编译你的应用程序,改变你 的build target为API8,这是必须的,因为老版本的android 类库不能够 解析android:installLocation 这个属性,这样就不能编译你现有的应用程序。

当你的设备是低于android2.2的,那个标签会被忽略,应用程序会安装到内存中。


Applications that should not install on external storage
应用程序不应该安装到外部存储的情况

当手机通过usb连接电脑分享文件的时候(或者移除SD卡的时候),安装在外存上正在运行的程序会被kill掉。
(以下简单就不翻译了)
Services 服务
Your running  Service will be killed 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.
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 小工具
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 its sync functionality will not work until external storage is remounted.
Device Administrators 设备管理员
Your  DeviceAdminReceiver and all its admin capabilities will be disabled, which can have unforeseeable consequences for the device functionality, which may persist after external storage is remounted.
Broadcast Receivers listening for "boot completed"   广播监听 引导完成
The system delivers the  ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast.
Copy Protection 拷贝保护
Your application cannot be installed to a device's SD card if it uses Android Market's Copy Protection feature. However, if you use Android Market's  Application Licensing instead, your application  can be installed to internal or external storage, including SD cards

If your application uses any of the features listed above, you should not allow your application to install on external storage. By default, the system will not allow your application to install on the external storage, so you don't need to worry about your existing applications. However, if you're certain that your application should never be installed on the external storage, then you should make this clear by declaring android:installLocation with a value of "internalOnly". Though this does not change the default behavior, it explicitly states that your application should only be installed on the internal storage and serves as a reminder to you and other developers that this decision has been made.


 
 
 
 
应用程序应该安装到外部存储的情况:
 
 
就是除了上述列出不能安装在外存的情况,安装到外存都是允许的了。特别是占用大量空间的游戏等。

In simple terms, anything that does not use the features listed in the previous section are safe when installed on external storage. Large games are more commonly the types of applications that should allow installation on external storage, because games don't typically provide additional services when inactive. When external storage becomes unavailable and a game process is killed, there should be no visible effect when the storage becomes available again and the user restarts the game (assuming that the game properly saved its state during the normal Activity lifecycle).

If your application requires several megabytes for the APK file, you should carefully consider whether to enable the application to install on the external storage so that users can preserve space on their internal storage.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值