How to use a function only if the version is 11+
Asked Answered
P

2

17

in my code i'm using the a function with "query text change" but it's only supported from android 11 this is a simple search bar. how to verify the current version of android, and show a different activity? thanks!

Pure answered 6/9, 2013 at 18:39 Comment(0)
S
30

There are many questions about that. Check Get Android API level of phone currently running my application and Programmatically obtain the Android API level of a device? . In these answers, you might see something like:

Integer.valueOf(android.os.Build.VERSION.SDK);

But .SDK has been deprecated. Use SDK_INT instead

//Check the condition as
if (android.os.Build.VERSION.SDK_INT>=11){}

See Build.VERSION.html#SDK_INT for more.

Update:

As kcoppock has nicely suggested, you may want to use something like:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
    //Do something
}
Schnitzel answered 6/9, 2013 at 18:41 Comment(1)
To be more verbose, you can use Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMBWunderlich
P
3

Build.VERSION.SDK_INT will tell you the SDK number.

Policyholder answered 6/9, 2013 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.