Android : Move to SD Card
Move to SD card is the feature which is introduced in Android 2.2. This feature allows system/user to optionally decide whether the application will be stored on phone’s internal memory or on SD card. This is configurable and allows user to decide anytime to move the application to SD card later after installation.
Let’s first see how it looks like.
On the phone with Android 2.2 and above, go to
Settings -> Applications -> Manage Applications.
This lists all the downloaded/installed applications. Clicking on any of the application the screen come up with the details of application something like the image here.
There are several button controls along with Move to SD card. This button allows user to explicitly move the application to SD card. This button will not enable by default and needs some configuration in the
AndroidManifest.xml file. Depending on the configuration, the behavior of this button will change on this screen.
Here are the details about enabling this button for your application.
android:installLocation attribute to
manifest tag as follows.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ajitmahajani.lightmeup" android:versionCode="1" android:versionName="1.0.0" android:installLocation="auto"> <uses-sdk android:minSdkVersion="4" /> ... </manifest>
Checkout the line #5 here. If this attribute is not present, the default behavior is to allow installation to internal storage only. This will not give option to user to move it to SD card.
Few things to note here. The
android:minSdkVersion in the above example is 4 and this feature is introduced in Android 2.2. So will it work? The answer is yes. However the button Move to SD card will be grayed out on the phones having Android below 2.2. One more important thing to note is that the build target needs to be updated to at least API Level 8 (since the feature is introduced in Android 2.2). Build target of the project can be updated from the Eclipse [Go to project properties by right clicking on it. Click on Android in the left page].
Note : To use this feature in the application DOES NOT require any
permission tag to be added the
android:installLocation can have following possible values.
"internalOnly": The application must be installed on the internal device storage only. If this is set, the application will never be installed on the external storage. If the internal storage is full, then the system will not install the application. This is also the default behavior if you do not define
"auto": The application may be installed on the external storage, but the system will install the application on the internal storage by default. If the internal storage is full, then the system will install it on the external storage. Once installed, the user can move the application to either internal or external storage through the system settings.
"preferExternal": The application prefers to be installed on the external storage (SD card). There is no guarantee that the system will honor this request. The application might be installed on internal storage if the external media is unavailable or full, or if the application uses the forward-locking mechanism (not supported on external storage). Once installed, the user can move the application to either internal or external storage through the system settings.
There are some type of applications which should NOT be installed on the external storage. Find the further details here.