Advertisement
Android SDK

Quick Tip: Enabling the Android Move To SD Card Feature

by

This Android Quick Tip will show you how to allow your end-users to optionally save valuable device storage space by choosing to store your application on their removable SD card.

Final Result Preview

This tutorial will take an existing Android application and add the ability for the user to move the application to their SD card. This feature was introduced in Android 2.2, but does not require the application to use the Android 2.2 SDK as the minimum supported SDK version. Even your Android 1.5 application can use this feature.

Step 1: Preparation

We begin this tutorial by obtaining the version of the phrasebook Android application used in a previous tutorial called Android SDK: Building a Localized Phrasebook. Download the source code if you want to perform these steps yourself, or just follow along and use these steps with your own Android applications.

If the user has Android 2.2 installed on their device and you haven’t applied this tip, they’ll see a tantalizingly useful, yet grayed out, button when they try to move the application to their SD card. Developers must specifically enable this feature within their specific applications.

Move to SD Card In App

Step 2: Modify the Manifest

Edit the AndroidManifest.xml file of the application to add an entry for “android:installLocation” to the <manifest> tag:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mamlambo.article.phrasebook" android:versionCode="2" android:versionName="1.0.1" 
android:installLocation="auto">
...
</manifest>

The value is set to “auto” so that the user can decide where to install the application. If this value is not present at all, the default behavior is to only allow installation to internal storage and not to give the user a choice. The other possible values to use are “internalOnly” which is the same as the behavior without this setting, and “preferExternal,” which will install the application on the SD card first, if it’s available and there is room.

Keep the “minSdkVersion” the same as before; it need not be 8 to match Android 2.2:

<uses-sdk android:minSdkVersion="7" />

Step 3: Update the Build Target

The build target, however, needs to be updated to at least API Level 8 (Android 2.2), otherwise you’ll get the following error:


error: No resource identifier found for attribute 'installLocation' in package 'android’

Change the build target by editing the project properties (right-click on the project in Eclipse), and choose a target with at least API Level 8:

Move to SD Card 2.2

Step 4: Load it Up

Now, load the application on a 2.2 device (or emulator). Go to the application management area and you’ll now see that it can be moved to the SD Card!

Move to SD Card available

When to Use This Feature

In the future, most Android applications should enable the ability for users to choose the application install location. However, for some applications, this feature doesn’t make as much sense. For example, if you have an app widget, live wallpaper, or other sort of service or utility application (such as a file manager), your application won’t be of any use if the SD card is removed. This is supported, though. For instance, a live wallpaper on the SD card will simply revert to the default wallpaper and the user can reselect your live wallpaper when the SD card is reinserted.

Although users may not remove their SD cards frequently, the SD card is unmounted when it’s 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. For a full list of apps that are affected when removed, see this Google Android reference.

Conclusion

Now your users can have the choice on whether or not to put your application on their SD card. Allowing this feature is important as users download more and more applications and fill up their Android devices with content. If you provide this option now, you’ll have a distinct advantage over other applications. It only takes a few minutes, yet enables a very powerful feature. I know I look for it; I’m constantly getting warnings about being low on space on my good old Nexus One.

Please, update your applications to allow this and resubmit them to the market. I’d appreciate it and so will the rest of your users!

About the Authors

Mobile developers Lauren Darcey and Shane Conder have coauthored several books on Android development: an in-depth programming book entitled Android Wireless Application Development and Sams TeachYourself Android Application Development in 24 Hours. When not writing, they spend their time developing mobile software at their company and providing consulting services. They can be reached at via email to androidwirelessdev+mt@gmail.com, via their blog at androidbook.blogspot.com, and on Twitter @androidwireless.

Need More Help Writing Android Apps? Check out our Latest Books and Resources!

Buy Android Wireless Application Development, 2nd Edition  Buy Sam's Teach Yourself Android Application Development in 24 Hours  Mamlambo code at Code Canyon

Related Posts
  • Code
    Mobile Development
    Inspecting iOS Applications with RevealPreview image@2x
    In this article, I'd like to tell you about Reveal, an OS X application created by Itty Bitty Apps that lets you inspect your application's user interface at runtime. Be ready to be amazed.Read More…
  • Code
    Android SDK
    Integrating Google Play Services on Android85ude preview image@2x
    By integrating your Android apps with Google Play Services, you can access Google services, such as Maps, Drive, and Google+. In this tutorial, we will go through the process of integrating Google Play Services with Android apps.Read More…
  • Computer Skills
    Electronics
    How to Clone Your Raspberry Pi SD Cards With WindowsRpi400
    The Raspberry Pi runs from an operating system stored on a Secure Digital (SD) card and many different operating systems may be employed. Storage is relatively inexpensive, can be created (flashed), recreated, written to and overwritten with ease. On the one hand, this is an advantage of the Pi. On the other, the experimental nature of the Pi means more time flashing SD cards. This tutorial shows you how to clone any Raspberry Pi SD card which is particularly useful when you have your OS set up just as you want it.Read More…
  • Code
    Android SDK
    Android SDK: Publishing and ReleasingAndroid preview@2x
    From the start of this series, we've been learning about creating Android applications. So far, we've focused on the development aspect as well as the tools you use to design, build, run, and test your applications. In this tutorial, we'll look at the process of distributing an application through the Google Play store. Of course, you need to make sure that your applications have been tested and debugged thoroughly before you get to this stage.Read More…
  • Code
    Android SDK
    Android SDK: SamplesAndroid preview@2x
    In this series, we have been exploring the basics of Android development. We have looked at what you need to know when building the elements in Android apps. In this tutorial, however, you will see that the Android platform provides resources you can learn from. The samples of the Android SDK include complete applications in which you can see functioning examples of typical Android application components. You can use the samples in more than one way, including directly from within Eclipse.Read More…
  • Code
    Android SDK
    Android SDK: App DataAndroid preview@2x
    In this series, we are learning about Android SDK development from scratch. We have already become acquainted with the structure and basic elements in an Android application, including the resources, Manifest, and user interface. As soon as you start to develop functional apps for Android, you will need to store data of one kind or another. The Android platform offers a range of options for data storage in your apps, which we will examine in this tutorial.Read More…