GoogleマップがGPSを有効にするようにユーザーに促すことができたことに気づきました。私はこのメソッドを以下で試してみましたが、一度だけプロンプトが表示されたら何もしません...なぜ、onActivityResult()メソッドがもう呼び出されないのですか?GPSを有効にするためのポップアップをユーザーに表示
public void checkLocationEnable() {
Log.e(TAG, "Here");
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
final PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
final LocationSettingsStates state = locationSettingsResult.getLocationSettingsStates();
Log.e(TAG, "state:" + state);
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
Log.e(TAG, "HERE-1");
// All location settings are satisfied. The client can
// initialize location requests here.
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.e(TAG, "REQUIRED");
// Location settings are not satisfied, but this can be fixed
// by showing the user a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(
getActivity(),
GenericActivity.REQUEST_LOCATION);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way
// to fix the settings so we won't show the dialog.
Log.e(TAG, "UNAVALAIBLE");
break;
}
}
});
}
ユーザーがダイアログボックスに応答すると、このメソッドは結果を受け取るように、onActivityResultメソッドをオーバーライドする必要があります。 –
私はそれをActivityHome – Jaythaking
[this](http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is)で上書きします-enabled/843716#comment63478757_843716)あなたが求めていることをします。 – TDG