Check Android.os.Build.VERSION
You can find out the Android version looking at
Build.VERSION
.The documentation recommends you check
Build.VERSION.SDK_INT
against the values inBuild.VERSION_CODES
.This is fine as long as you realise that
Build.VERSION.SDK_INT
was only introduced in API Level 4, which is to say Android 1.6 (Donut). So this won't affect you, but if you did want your app to run on Android 1.5 or earlier then you would have to use the deprecated Build.VERSION.SDK
instead.Example how to use it:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
// only for android older than gingerbread
}
Build.VERSION.RELEASE;
That will give you the actual numbers of your version; aka 2.3.3 or 2.2. The problem with using Build.VERSION.SDK_INT is if you have a rooted phone or custom rom, you could have a none standard OS (aka my android is running 2.3.5) and that will return a null when using Build.VERSION.SDK_INT so Build.VERSION.RELEASE will work no matter what!
No comments:
Post a Comment