views:

340

answers:

1

We're building an Android app with target SDK 1.6, so it will run on 1.6 devices and higher. We'd like to support Live Wallpapers, which we know is 2.1+ only. Is there a way to build one app with 1.6 SDK as the target, but detect if the device it's running on is 2.1, and only in that scenario call the live wallpaper API.

We're trying to avoid having to build a separate 1.6 and 2.1 versions, and would like to be able to support Live Wallpapers for only 2.1 devices. So to be clear- 1 app, that can support 1.6 and higher, and support live wallpapers for 2.1 devices.

Any way of doing this?

+2  A: 

Maybe. I haven't worked with Live Wallpapers, but here is how I use the AccountManager on 2.* but have a fallback on 1.* where it isn't available.

I build with the 2.1 SDK, but my Manifest states

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

This does allow the app to run on 1.5 devices upwards.

I restrict my use of android.accounts.AccountManager to a wrapper class, I called it UserEmailFetcher.

It will be possible to use this class on 2.* devices. However on earlier devices a java.lang.VerifyError will fire the first time this class is encountered in the code. This I catch, and perform some fallback action.

String name;
try {
   name = UserEmailFetcher.getEmail(this); 
} catch (VerifyError e) {
   // Happens if the AccountManager is not available (e.g. 1.x)
}

Hope that helps.

Jim Blackler
Great, that worked, thanks!!
itamarw
Glad it worked for you! Don't forget you can mark answers 'accepted' by clicking the check/tick symbol!
Jim Blackler
Oh right, I'm a noob, sorry ;)
itamarw