Getting device os version in Android programmatically

前端 未结 5 1734
长发绾君心
长发绾君心 2020-12-01 13:35

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 versi

相关标签:
5条回答
  • 2020-12-01 14:06

    Try This,

        String deviceOs = android.os.Build.VERSION;
    

    I hope this will help.

    0 讨论(0)
  • 2020-12-01 14:10

    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
    
    0 讨论(0)
  • 2020-12-01 14:15

    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 讨论(0)
  • 2020-12-01 14:28

    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

    0 讨论(0)
  • 2020-12-01 14:28
    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.

    0 讨论(0)
提交回复
热议问题