gpt4 book ai didi

android - 当我们从顶部状态栏启用位置时如何关闭 LocationSettingsRequest 对话框?

转载 作者:搜寻专家 更新时间:2023-11-01 08:22:37 31 4
gpt4 key购买 nike

This is my sample code for prompting the user for to enable GPS location.

 private void showLocationSettingsRequest(Context context) {
try {
/* Initiate Google API Client */
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(SPPlaysetScanActivity.this)
.addApi(LocationServices.API)
.build();
googleApiClient.connect();

LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(10000 / 2);

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);

PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
// Show the dialog by calling startResolutionForResult(), and check the result in onActivityResult().
status.startResolutionForResult(SPActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.d(TAG, "showLocationSettingsRequest :PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Log.d(TAG, "showLocationSettingsRequest :Location settings are inadequate,
// and cannot be fixed here. Dialog not created.");
break;
}
}
});

} catch (Exception e) {
Log.d(TAG, "showLocationSettingsRequest EX:" + e.toString());
}
}

If we disable location from status bar setting we are able to get the location settings dialog but when we turn on location (from the top status bar) but still the location dialog appears. I need to dismiss dialog when the location is turned on from status bar settings.

提前致谢!

最佳答案

这在您的代码方面是不可能的。调用:

status.startResolutionForResult(SPActivity.this, REQUEST_CHECK_SETTINGS);

您正在打开单独的 Activity(来自 Google Play 服务库)。此代码应该足够智能,注册 BroadcastReceiver 以进行位置更改,然后将结果返回到您的 Activity(如果 GPS 已启用)。

由于您无法更改此代码,我想您需要做的是在 Google 问题跟踪器网站上编写更改请求:https://source.android.com/setup/report-bugs

关于android - 当我们从顶部状态栏启用位置时如何关闭 LocationSettingsRequest 对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48946146/

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