从android 2.2 开始,打开“程序管理”,可以进行app2sd。但是,有的程序的这个选项是灰色,无法选择,有的可以。
经过查找SDK文档,我找到原因了。需要再程序里添加一句代码,就可以使你的程序随意移动。就是下面这句代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >
下面是SDK文档关于android:installLocation的详细内容。
App Install Location
Quickview
- You can allow your application to install on the device's external storage.
- Some types of applications should not allow installation on the external storage.
- Installing on the external storage is ideal for large applications that are not tightly integrated with the system (most commonly, games).
In this document
- Backward Compatibility
- Applications That Should NOT Install on External Storage
- Applications That Should Install on External Storage
See also
Beginning with API Level 8, you can allow your application to be installed on the external storage (for example, the device's SD card). This is an optional feature you can declare for your application with theandroid:installLocation
manifest attribute. If you do not declare this attribute, your application will be installed on the internal storage only and it cannot be moved to the external storage.
To allow the system to install your application on the external storage, modify your manifest file to include theandroid:installLocation
attribute in the <manifest>
element, with a value of either "preferExternal
" or "auto
". For example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >
If you declare "preferExternal
", you request that your application be installed on the external storage, but the system does not guarantee that your application will be installed on the external storage. If the external storage is full, the system will install it on the internal storage. The user can also move your application between the two locations.
If you declare "auto
", you indicate that your application may be installed on the external storage, but you don't have a preference of install location. The system will decide where to install your application based on several factors. The user can also move your application between the two locations.
When your application is installed on the external storage:
- There is no effect on the application performance so long as the external storage is mounted on the device.
- The
.apk
file is saved on the external storage, but all private user data, databases, optimized.dex
files, and extracted native code are saved on the internal device memory. - The unique container in which your application is stored is encrypted with a randomly generated key that can be decrypted only by the device that originally installed it. Thus, an application installed on an SD card works for only one device.
- The user can move your application to the internal storage through the system settings.
Warning: When the user enables USB mass storage to share files with a computer or unmounts the SD card via the system settings, the external storage is unmounted from the device and all applications running on the external storage are immediately killed.
我们可以添加android:installLocation="preferExternal"或者android:installLocation="auto"。如果什么都不写,就默认为android:installLocation="internalOnly",这个就是只将程序安装在手机内存里,所以,不可移动。
原文地址:点击打开链接