Mittwoch, 23. November 2011

App Install Location Trick for Android

This post will show you how to easily target users on older platforms but still enable the external storage feature for your Android app.
You should know about the things discussed here: Managing Android projects from Eclipse with ADT
In order to give users the option to install your app to external storage (e.g. SD card) you must set the build target to API level 8 or higher (look here if you don't know how to do that). Only then you can set the installLocation attribute in the AndroidManifest.xml to preferExternal which enables this feature.

<manifest xmlns:android=""

But of course you don’t want to exclude users on older platforms because they still have significant market share. The solution is to set mindSdkVersion to something lower than 8.

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

Even though this works it is not that nice to work with. Why? Because now you must watch out which API components you use and which not. Remember the build target is still set to at least 8 for the installLocation attribute to work so Eclipse will allow you to use that API even if you don’t actually want to.

But you can work around this by using an Android library project AND a standard Android project.

The library project contains all your code. This is actually your app. It’s build target is set to the minimum API level you’re aiming for. Now when you code you can not even use any newer API components because Eclipse will prevent you from doing so.

The standard project contains no code at all but references the library project. Here you take care of enabling the external storage feature (build target >= 8, mindSdkVersion < 8). Also you have to make sure that all your activities, services, etc. are declared in it’s AndroidManifest.xml for this is the actual project you will execute.

What you now have is an app that must be built by using 2 projects. One project is dedicated to your programming, the other to enabling the external storage feature.

Now go and build awesome apps I can install on my SD card :)

Keine Kommentare:

Kommentar veröffentlichen