This tutorial will focus on how to move apps to SD card in android. Moving applications from the internal memory to external SD card was introduce in android 2.2. This feature allows users and android system the opportunity to choose where an app should be installed in android device.
It is important to note that this feature was removed in android 4.0 – 4.2 and was later reintroduced in android 4.3 but on specific phones.
Why would you want to move some app from internal memory to SD card? If you have many apps in your android device that take too much space and slow your device down, you can choose to move some of these apps to SD card to free up some space in internal memory.
Let start with trying to find out how we can accomplish this simple task. The simple way to do this is to go to your phone’s setting, click on application and then manage application and you will see a button called “Move to SD card” when you select an application in the list of your installed applications.
If an application is not set to be move to SD card it means that this button may be missing or inactive.
The simple images below show how to move an app from internal memory to SD card.
Since we have dealt with how this can be done in our phone, now is the time to create a new application and demonstrate how we can make our android app to support “Move to SD card” button.
I used the following environment and tools in this tutorial but you are free to use whatever tools you are familiar with.
Samsung Galaxy Fame Lite
Min SDK 8
Target SDK 19
There is no better time to start creating our application than now. To create a new android application project, following the steps as stipulated below.
Go to File menu
Click on New menu
Click on Android Application
Enter Project name: AppToSDCard
Keep other default selections
Continue to click on next button until Finish button is active
Then click on Finish Button
Once you are done with your project setup, we will only add a single line of code in our project manifest file. Open your application manifest file and copy and paste this code as shown below.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.inducesmile.apptosdcard.apptosdcard" android:versionCode="1" android:versionName="1.0" android:installLocation="auto"> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
The application attribute – android:installLocation is what helps the android system to understand where an app needs to be install. There are many values you can pass to this attribute. In other to understand it more and a clearer view about what each value does, I will reference the android use guide. One important thing to know is that you do not need any permission when you implement this feature. The following values can be passed – internalOnly auto and preferExternal
“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 android:installLocation.
“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. Once installed, the user can move the application to either internal or external storage through the system settings.
If you have questions or suggestions, kindly use the comment box below. You can also download the complete source code for this application here.