开发者

Getting device os version in Android programmatically

How can I get the current android device version (1.5, 1.6, 2.0, etc.) programmatically? i.e I have installed my apk on an Android 2.2 device. I need to get the device开发者_C百科 version (android emulator version in which my application is currently running ).


Something like these:

String myVersion = android.os.Build.VERSION.RELEASE; // e.g. myVersion := "1.6"
int sdkVersion = android.os.Build.VERSION.SDK_INT; // e.g. sdkVersion := 8; 

You can retrieve all SDK codes from Build.VERSION_CODES


int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
    // Do something for lollipop and above versions
} else{
    // do something for phones running an SDK before lollipop
}

By this code we can execute separate code for Pre Lollipop devices.


If you want to see the firmware version number then you can use

Build.VERSION.SDK_INT

But if you want firmware version name then you should use something like this

Build.VERSION_CODES


Try This,

    String deviceOs = android.os.Build.VERSION;

I hope this will help.


Take a look at the Build.VERSION version class. Depending on what you want to do, you might want to use the RELEASE or SDK_INT attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜