I'm trying to get the SDK version of an application, but if I test
android.os.Build.VERSION.SDK_INT
in an application targeted for 2.3.3, I get the device's version which is 17 instead of 10.
I don't know the SDK version that my code will be compiled with, because I'm writing a code snippet that developers can add to their own application.
Thanks.
You should always target for latest version. That will bring you the latest API. I guess you need to know the current version of the API available on the device. For that you would do something like this (to check if current API is 2.3):
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static void someMethod() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
/**
* Call code accessible from Gingerbread onwards
* */
} else {
/**
* Call code from previous API
* */
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With