这个问题已经在这里有了答案: > How do I get the current GPS location programmatically in Android? 22个
我尝试过在线搜索答案,但它们似乎仅适用于AndroID 4.0及以下版本
解决方法:
public static boolean isLocationEnabled(Context context) { int locationMode = 0; String locationProvIDers; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ try { locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (SettingNotFoundException e) { e.printstacktrace(); return false; } return locationMode != Settings.Secure.LOCATION_MODE_OFF; }else{ locationProvIDers = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return !TextUtils.isEmpty(locationProvIDers); }}
总结 以上是内存溢出为你收集整理的java-如何检查是否在Android 4.4及更高版本中以编程方式打开了gps?全部内容,希望文章能够帮你解决java-如何检查是否在Android 4.4及更高版本中以编程方式打开了gps?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)