gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:23:04 24 4
gpt4 key购买 nike

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

is there any way to check checkLocationSettings dialouge is showing already? how to prevent dialouge showing multiple times

最佳答案

您可以在显示权限对话框之前检查位置权限和位置服务。

检查位置权限

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);
}
}

关于android - 多次显示谷歌位置设置对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45917439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com