Skip to content Skip to sidebar Skip to footer

Android App Using 2.x Apis That Will Also Run On 1.x

I'm working on an Android app in which I would like to use multi-touch. However, I do not want to completely leave out those still running a 1.x OS phone. How do you program the a

Solution 1:

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-sdkandroid: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.

Solution 2:

There's a good Android article on this topic called "Backward Compatibility for Applications." Essentially there are two things you can do:

  1. Set the minSdkVersion so that the app identifies itself as being compatible with a version of Android lower than what it was compiled on.

  2. Use reflection to access newer APIs.

You can also create a wrapper class for speed/ease of use, but that's just a flavor of #2.

As for platform usage, Google released this data a few months ago.

Solution 3:

Using reflection seems to be the way to go :) Hello p2p Android Wifi in API level 14

http://developer.android.com/resources/articles/backward-compatibility.html

Post a Comment for "Android App Using 2.x Apis That Will Also Run On 1.x"