1

I've got a native interface with two reasons I need to have the device's SDK level. The first is that some methods were deprecated and so I need to determine if the device has a high enough version for the new API, and the second is that a new permission is required for SDK level 23 but adding that permission on devices with

I've tried statements like this below, but I don't think it's working:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)

I've also tried the above with just the integer representing the level, such as 18 for JELLY_BEAN_MR2. Is there an AndroidNativeUtil for this? I can't find any documentation about what classes are in AndroidNativeUtil.

The reason I don't think it's working is that when I add these statements to control which API is used, the app works OK on a newer device with the higher API level, but hangs on a device with the older API level. I'm assuming that it must always think the API > 18.

1 Answer 1

1

The String Build.VERSION.RELEASE will give you the user-visible version string (i.e 1.5, 1.6, 2.0), while Build.VERSION.SDK_INT will give you a value from Build.VERSION_CODES that would be better to use if you want to compare against it programmatically.

Note that Build.VERSION.SDK_INT is only available on Android 1.6 and newer. Build.VERSION.SDK will work on all Android releases, including 1.5. However, once you elect to drop 1.5 support, switching to SDK_INT is a good idea.

EDIT:

StringBuffer buf = new StringBuffer();

buf.append("VERSION.RELEASE {"+Build.VERSION.RELEASE+"}");
buf.append("\\nVERSION.INCREMENTAL {"+Build.VERSION.INCREMENTAL+"}");
buf.append("\\nVERSION.SDK {"+Build.VERSION.SDK+"}");
buf.append("\\nBOARD {"+Build.BOARD+"}");
buf.append("\\nBRAND {"+Build.BRAND+"}");
buf.append("\\nDEVICE {"+Build.DEVICE+"}");
buf.append("\\nFINGERPRINT {"+Build.FINGERPRINT+"}");
buf.append("\\nHOST {"+Build.HOST+"}");
buf.append("\\nID {"+Build.ID+"}");

Log.d("build",buf.toString()); 
Sign up to request clarification or add additional context in comments.

3 Comments

I've tried the SDK_INT and compared it to 21, but the results don't change. I'll have to set up a Toast message or something so I can get the results.
This should work, I'm guessing the reason for the hanging is different. This Friday we improved support for the location API's on older devices so this might be related to that issue. If not try connecting the older device with DDMS and looking at the log.
I wrote a simple test case to show the results of the Build.VERSION.SDK_INT call in a dialog using a native interface, and it is working as expected, returning the integer value of the API level. The problem must be with my other code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.