39

Possible Duplicate:
Retrieving Android API version programmatically

I am trying to retrieve the current API Version of the device my Application is Running. Is there a way i can get that and Store it on a String. This needs to Work on 1.5 Version and Up. Examples would be greatly appreciated. Thank you.

1

3 Answers 3

72

You can get it by calling Build.VERSION.SDK.

From 1.6 on, you should use Build.VERSION.SDK_INT instead
because Build.VERSION.SDK is deprecated.

Sign up to request clarification or add additional context in comments.

4 Comments

Awesome Thanks A Bunch for the quick response
Deprecated - yes. But how should I determine I got Cupcake or lower? Accessing SDK_INT fails on devices prior to Donut, as it was defined in API Level 4!
Check out my answer on other question for code - stackoverflow.com/questions/3423754/…
The enum corresponding to this int is in the android.os.Build.VERSION_CODES class. int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){ // Do something for froyo and above versions } else{ // do something for phones running an SDK before froyo } Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).
22
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!

1 Comment

wouldn't SDK_INT return 0 not null?
20

It is defined on the android.os.Build.VERSION.SDK constant, just use it.

2 Comments

+1 for drawing faster :)
Awesome Thanks A Bunch for the quick response

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.