Android app using API 2.x which will also work on 1.x
I am working on an Android application where I would like to use multi-touch. However, I don't want to completely rule out those who are still running the 1.x OS phone. How do you program your application so that you can use 2.x multi-touch APIs (or any other higher level API) and still allow graceful degradation on 1.x systems. If you build a project in Eclipse for 1.x, can you even access the 2.x API? Basically I want it to hit the market and work on all 1.6 and higher phones and just allow access to higher level features if available.
Also, if someone can point me to any data on the number of 1.x or 2.x devices in use, it will be very helpful.
source to share
This is how I use the AccountManager on 2. * but have a reserve on 1. * where it is not available.
I am building with 2.1 SDK but my manifest states are
<uses-sdk android:minSdkVersion="3" />
This allows 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.
This class can be used on 2. * devices. However, on earlier devices, java.lang.VerifyError will fire the first time this class is encountered in code. I will catch this and perform some kind of backup action.
String name;
try {
name = UserEmailFetcher.getEmail(this);
} catch (VerifyError e) {
// Happens if the AccountManager is not available (e.g. 1.x)
}
Hope it helps.
source to share
There's a good Android article on this topic called " Backward Compatibility for Applications ." Essentially, you can do two things:
-
Set minSdkVersion to make the application identify itself as compatible with Android version lower than it was compiled.
-
Use reflection to access newer APIs.
You can also create a wrapper class for speed / ease of use, but that's just flavor # 2.
In terms of platform usage, Google released this data a few months ago .
source to share
Using reflection seems like the way to go :) Hi p2p Android Wi-Fi in API level 14
http://developer.android.com/resources/articles/backward-compatibility.html
source to share