我正在创建一个GPS应用程序,我试图检查运行该应用程序的devce是否在版本4.2.2或更低版本上运行。 如果是这样,应用程序可以通过命令
自行打开/关闭GPS服务Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
现在,如果设备运行的版本高于4.2.2,则用户将收到一条连接他的pupout消息,以便手动打开GPS。 感谢。
答案 0 :(得分: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
}
以下内容虽然可以为您提供更精确的数字,例如4.2.2,但上面的内容会对API级别进行粗略检查。
Build.VERSION.RELEASE;
http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
http://developer.android.com/reference/android/os/Build.VERSION.html