慕娘9325324
是的,GPS设置不能再以编程的方式改变,因为它们是隐私设置,我们必须检查它们是否是从程序中打开的,如果它们没有打开,我们必须处理它们。您可以通知用户GPS已关闭,并使用类似的东西来显示设置屏幕给用户,如果你愿意的话。检查位置提供程序是否可用 String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider != null){
Log.v(TAG, " Location providers: "+provider);
//Start searching for location and update the location text when update available
startFetchingLocation();
}else{
// Notify users and show settings if they want to enable GPS
}如果用户希望启用GPS,您可以这种方式显示设置屏幕。Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);startActivityForResult(intent, REQUEST_CODE);在onActivityResult中,您可以看到用户是否启用了它 protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == REQUEST_CODE && resultCode == 0){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider != null){
Log.v(TAG, " Location providers: "+provider);
//Start searching for location and update the location text when update available. // Do whatever you want
startFetchingLocation();
}else{
//Users did not switch on the GPS
}
}
}这是一种方法,我希望它有帮助。如果我做错了什么,请告诉我。