-1

I need to check the Android version of my phone and if the version is less than 4.0.0 i should execute the following code otherwise it should not execute. How could I do it? I used this line to get the Android version.

String androidOS = Build.VERSION.RELEASE;

How could I check whether less than 4.0.0. Suggest me a solution.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ssh
  • 51
  • 1
  • 1
  • 11

4 Answers4

23

Something like this :

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

}

and for more version check out here!

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41
8

You can get any detail about phone like this -> and android.os.Build help you to get this

 System.out.println("button press on device name = "+android.os.Build.MODEL +" brand = "+android.os.Build.BRAND +" OS version = "+android.os.Build.VERSION.RELEASE + " SDK version = " +android.os.Build.VERSION.SDK_INT);
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
7

use

 int currentapiVersion = android.os.Build.VERSION.SDK_INT;


    if (currentapiVersion >= 14) {
        // Do something for 14 and above versions


    } else {

         // do something for phones running an SDK before 14

    }
Supriya
  • 1,078
  • 1
  • 8
  • 16
2

Try below code:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD){
    // Do your code for froyo and above versions
} else{
    // do your code for before froyo versions
}
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44