Storing your Android app on the device's SD card

One of the downsides to Titanium is that, due to its compilation process, applications built on the Titanium platform tend to be rather large in file size in comparison to a native app. Most simple apps in Titanium will range from between 4-5 megabytes in size. This is not really a problem for an iPhone, but unfortunately many Android devices utilize SD card memory and do not have much in the way of local phone storage space.

In this recipe, we will show you how to configure your Android application in order for it to run on the SD card, via Android's Move to SD card button in the application settings screen.

Note

Complete source code for this recipe can be found in the /Chapter 8/Recipe 7 folder.

How to do it…

Open the tiapp.xml file under your project's root directory and find the <android> node in the XML which will be located near the bottom of the file. Alter the <android> node so it looks like the following code:

<android xmlns:android="http://schemas.android.com/apk/res/android">
  <tool-api-level>8</tool-api-level>
  <manifest android:installLocation="preferExternal">
    <uses-sdk android:minSdkVersion="7" />
  </manifest>
</android>

Now build and run your application on your Android device. Note that this may not work in the emulator.

How it works…

There are a few important parts to understand in relation to this XML configuration. The first is that the <tool-api-level> node value is actually referring to the minimum version of the Android tools required. Version 8 is the minimum needed to enable the external storage functionality.

The <android:installLocation> attribute refers to the initial storage of the application upon installation. Here we are telling the Android OS that we prefer it to be stored externally to an SD card. However, if one is unavailable, the app will be stored directly to the phone memory. You can also use a value of internalOnly, which would disallow the app from being installed on external memory.

Finally, the <uses-sdk> node refers to the version of Android required. Version 7 in this case refers to Android 2.1 and up, which is required in order to perform the Copy To SD-Card action.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.239.166