How to create android app with movable to SD Card feature?

In this post, You will learn how to create an Android application that comes with a feature to move it to SD Card.
If you specify minimum SDK to API Level 8 for your application, you can easily allow your application to be installed on the external storage (for example, the device's SD card).
There are many applications that provide the facility to users to choose the application install location (Internal memory or SD card). However, In some cases, you might no enable this feature.
For example, if you have a live wallpaper app or an app widget, or other sorts of service or utility application (such as a file manager), your application won’t be of any use if the SD card is removed from the device.
Although users do not remove their SD cards mostly, sometimes the SD card is unmounted when it is mounted via USB for use on a computer. This will potentially increase the frequency that the user will have to reconfigure apps that are affected. 
To get more info about whether you should allow this feature or not you may read this documentation: Applications that should NOT install on external storage

How to enable the move to SD card feature?

It's very simple and easy to enable the move to SD card feature in Android applications, all you need to do is specify the install location attribute in Android manifest as ‘auto’


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.blogspot.atifsoftwares.sqlite"
    android:installLocation="auto">
    ....
</manifest>



How to create android app with movable to SD Card feature?




The installLocation attribute can be assigned with the following values:

internalOnly:

It is the default behavior. If you’re certain that your application should never be installed on the external storage, then assign installLocation attribute value as "internalOnly".

preferExternal:

If you declare installLocation to "preferExternal", it means you requested 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 Internal or External(SD Card).

auto:

If you declare installLocation to "auto", you indicate that your application can 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 Internal or External(SD Card).

Comments

Popular posts from this blog

Picture In Picture | Android Studio | Kotlin

Manage External Storage Permission | Android Studio | Kotlin

Add a Back Button to Action Bar Android Studio (Kotlin)