我有一个使用location的android应用程序。但我注意到,如果用户在“设置”>“位置访问”中禁用了“访问我的位置”,那么什么都不会起作用。如何检查它是否已启用?如果它被禁用,如何在我的应用程序中打开这些设置?
谢谢
已解决:
String locationProviders = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (locationProviders == null || locationProviders.equals("")) {
...
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
发布于 2013-08-09 23:48:32
也许这将是有用的检查这个网站,它讨论位置服务
发布于 2013-08-09 23:49:43
你可以这样检查它:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) // Return a boolean
编辑:
如果您要检查网络提供商:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) // Return a boolean
编辑2:
如果要打开设置,可以使用以下方法:
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
发布于 2016-04-01 22:42:36
另一种不使用Settings.Secure
也不扫描所有位置提供商的方法是:
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
int providersCount = locationManager.getProviders(true).size(); // Listing enabled providers only
if (providersCount == 0) {
// No location providers at all, location is off
}
https://stackoverflow.com/questions/18150613
复制相似问题