谷歌位置显示设置对话框中多次

问题描述:

PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build()); 

有没有什么办法来检查checkLocationSettings的台词是显示了吗? 如何预防的台词显示多次谷歌位置显示设置对话框中多次

您可以检查显示Permission Dialog前的位置许可和位置服务。

检查位置的权限

public static boolean isLocationPermissionAvailable(Context context) { 
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { 
     return true; 
    } 

    return (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED); 
} 

检查位置服务启用

public static boolean isLocationEnabled(Context context) { 
    // Check if Current Device's SDK Version is Kitkat (Android 4.4 = API 19) & above 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     int locationMode = 0; 
     try { 
      locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); 
     } catch (Settings.SettingNotFoundException e) { 
      e.printStackTrace(); 
     } 

     return locationMode != Settings.Secure.LOCATION_MODE_OFF; 

    } else { 
     LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); 
     return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && 
       locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
    } 
} 
+0

我在递给同样的方式,但播出的问题接收机被调用很多次,感谢投入。我修好了 – John