-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.

1

4 Answers 4

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!

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

Comments

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);

Comments

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

    }

Comments

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
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.