API Development

Installing Android apps to the SD card

Editor’s note: This blog post is a basic tutorial, a more update version of this tutorial is always available on the wiki.

Your Android apps are installed by default to the device’s internal storage. But that limited space can fill quickly, especially on older devices like my Motorola Droid original. Fortunately, you can configure your Titanium apps to install to the SD card.

To do so, you need to modify the AndroidManifest.xml configuration file. Titanium makes this easy: you simply update your tiapp.xml file and Studio will take care of creating the necessary manifest file. Locate the <android> node near the end of that file. You’ll need to add a couple of properties and tags. When you’re done, it should look like this:

Build and deploy your app to a device. As the screenshot shows, your app should be installed to the SD card (though that’s not guaranteed, read on).

Let’s go over that code, because you can control a few options. First, the <tool-api-level> node specifies the version of the Android development tools that will be used to compile your app’s code. At minimum, you must specify version 8. Higher (newer) versions aren’t necessary for installing to the SD card, but perhaps offer other benefits.

Next, is the <manifest> node and the android:installLocation property. You’d choose one of these values for that property:

  • android:installLocation="preferExternal" — specifies that you prefer your app to install to the SD card, but if one isn’t present the app can be installed to internal storage.
  • android:installLocation="auto" — specifies that the phone’s configuration will determine the installation location. Generally, your app will be installed to internal storage if sufficient space is available. In that case, users could still move your app by opening Settings > Applications > Manage applications, tapping your app, and tapping Move to SD card.
  • android:installLocation="internalOnly" — which specifies that your app cannot be installed to the SD card. See the Android docs for the various reasons why you might choose this option.

Finally, you need to add the <uses-sdk> tag within the <manifest> node. This tag specifies that your app requires Google’s version 7 or newer APIs — in other words, the phone must be running Android 2.1 Update 1 or newer. That pretty much covers all the newer phones, but will exclude some older devices. On those phones, your app will install to the internal storage.

Keep in mind that even if your app is installed to the SD card, application data (such as your database) will still be stored on the device. For more details, visit this Android docs page.