Try Tuts+ Premium, Get Cash Back!
Quick Tip: Enabling the Android Move To SD Card Feature

Quick Tip: Enabling the Android Move To SD Card Feature

Tutorial Details
  • Technology: Eclipse + Android SDK
  • Difficulty: Beginner
  • Estimated Completion Time: 5-10 Minutes

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

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.emagenstudios.com Jesse

    Very cool. Looks pretty easy. I’ll have to mess around with this tonight when I get home.

    Thanks.

  • http://www.stealthcopter.com/blog Mat

    This was really useful, shall be including it on all my apps now. Thanks!

  • Anon

    Very quick, concise, and useful. Thank you for writing it up and posting it!

  • http://none Ken

    When I publish my app…..then it's useless….why?

  • http://www.blundell-apps.com Blundell

    A little note, if you select “content protection” in the app market, then even if you have the sd card opntion written into your manifest you still won’t be able to move it to your SD.

  • disgruntled reader

    Why use a bit.ly link when you are already making the text a hyperlink? It is useless redirection and prevents people from seeing what website they are opening before they click the link…

    • http://androidbook.blogspot.com/ Shane Conder & Lauren Darcey
      Author

      Thanks for the feedback. We’re sorry you don’t like the bitly links.

      Bitly provides an extensive set of tracking tools for links. As authors, we find the statistics invaluable. It’s the only way to consistently — and easily — track links across print and online media and multiple publishers.

  • http://Www.spiritproject.com Nikolai

    Thank you for sharing…google showed your post first and exactly what I was looking for. Build target to 2.2…Forgot to set it;)

  • SultanSh

    Thanx That was very usefull

  • Shawn

    That’s amazing .. but i have a confusion..If My app has MinSDK 4 .. but here needs 7 .. and you have said that this trick can be useful for the Android 1.5 as well which uses MinSDK 3.. .. and if i change the SDK 3 to 7 then it wont be working on the devices having Android 1.6…. whats the solution ?

    • http://androidbook.blogspot.com/ Shane Conder & Lauren Darcey
      Author

      Hi Shawn,

      Older versions of Android that don’t support this feature will still load and run with the setting turned on in the manifest file. So, if you’re asking how to allow this feature on older versions of Android, you can’t as, by definition, it’s a feature added in later versions of Android.

      I hope this makes sense.

      • Ashwin

        This setting cannot be turned on in the Manifest without setting the minSdkVersion to 7. So there is no question of older versions of android running this app after that.

      • MattC

        Hi. My question is (and maybe his too) : “Can I activate this option, and keep this application usable by Android 1.5 users ?”

  • ubuntudroid

    It should be noted, that when changing the mentioned values using Eclipse, it is sometimes necessary to clean the project before it compiles without errors.

  • Ilias

    so does it work with android 1.5?

  • Mark Kamoski

    Dear Shane and Lauren –

    Please help.

    Do you happen to know how one could do this process of setting the installLocation in the manifest of an APK that was created with App Inventor?

    Please advise.

    Thank you.

    - Mark Kamoski

  • http://MKamoski1.WordPress.com/ Mark Kamoski

    All -

    FYI, this is a reply in answer to my previous question of “February 27, 2011 at 10:51 pm”.

    I had asked setting Install To SD for an app created with App Inventor.

    As of now, there are at least 2 App Inventor App packaging tools that can do the trick, as follows…

    AppToMarket

    http://amerkashi.wordpress.com/

    Marketizer

    http://www.taiic.com/2011/02/20/marketizer-2-01-is-available-for-download/

    …and I have used the both and they both are excellent.

    (Those links may not be permanent; but, they will get you close– or just Google the names.)

    HTH.

    Thank you.

    - Mark Kamoski

  • Thomas

    Thanks a lot Mark for your own answer, you just helped a french developper, me ! ;o)

  • http://officerbrooks.com Mark A. Brooks

    Does this method utilize the Application Licensing protocol so tat the app can’t be duplicated for unauthorized users?

  • Scott

    So if you’re not a “computer” expert, forget it??? This all sounds greek to me. My wife bought me a Pandigital 7″ tablet and the memory quickly filled. We bought a 32GB SD card, but I can’t see how to move the “stuff” into that external storage.

    I get that gray’d out option to move it, but it doesn’t work.

    Can somebody tell me in “stupid” people language how to do it on my device?

    • Michael

      Scott:

      If you look at the first lines on this article, it says that these are instructions for how developers can make this option available for end-users.