-2

im creating a GPS app , im trying to check if the devce that runs the app runs on version 4.2.2 or lower . if so the app can turn on / off the GPS service by it self with the command

Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);

now if the device runs a version higher then 4.2.2 , the user will get a pupout message that link him for the manual turn on of GPS. thanks.

wafihsn
  • 5
  • 4

1 Answers1

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

The following though would give you a more exact number like 4.2.2 whereas the above one will make a rough check on the API level.

Build.VERSION.RELEASE;

http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

http://developer.android.com/reference/android/os/Build.VERSION.html

Pavlos
  • 2,183
  • 2
  • 20
  • 27