我的应用程序的一部分需要位置服务,因此,如果当前关闭了位置信息,则该应用程序将提示用户启用它。这是我的操作方式:(也在此堆栈溢出答案中看到)
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>()
{
@Override
public void onResult(LocationSettingsResult result)
{
final Status status = result.getStatus();
final LocationSettingsStates = result.getLocationSettingsStates();
switch (status.getStatusCode())
{
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
...
Log.d("onResult", "SUCCESS");
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
Log.d("onResult", "RESOLUTION_REQUIRED");
try
{
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(OuterClass.this, REQUEST_LOCATION);
}
catch (SendIntentException e)
{
// Ignore the error.
}
break
}
}
});
该代码运行良好,但是onActivityResult()始终会被跳过。无论用户按Yes,No或back从Dialog,onActivityResult()不运行。
我需要Android来拨打电话,onActivityResult()因此,如果用户选择不打开位置服务,则可以适当地处理它。
Google的开发人员页面(以及上面的代码)明确表示onActivityResult()应调用该页面。有人知道为什么它被跳过吗?
我也不知道这行的目的是:
final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
30秒到达战场
白板的微信
相关分类