Schritt 10:
Jetzt nur kopieren und einfügen folgenden Code außerhalb Oncreate Methode...
private GoogleApiClient GoogleApiClient;
Jetzt nur kopieren und einfügen folgenden Code in Oncreate...
Wenn (GoogleApiClient == Null) {}
GoogleApiClient = new GoogleApiClient.Builder(getApplicationContext()).addApi(LocationServices.API) .build(); googleApiClient.connect();
LocationRequest LocationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); LocationSettingsRequest.Builder Generator = neue LocationSettingsRequest.Builder() .addLocationRequest(locationRequest);
// **************************
builder.setAlwaysShow(true); Dies ist die wichtigste Zutat
// **************************
PendingResult Ergebnis = LocationServices.SettingsApi .checkLocationSettings (GoogleApiClient, builder.build()); result.setResultCallback (new ResultCallback)
{
public void OnResult (LocationSettingsResult Ergebnis)
{
endgültigen Status Status = result.getStatus();
LocationSettingsStates Endzustand = Ergebnis .getLocationSettingsStates();
Schalter (status.getStatusCode())
{
Fall LocationSettingsStatusCodes.SUCCESS:
zu brechen;
Fall LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
versuchen Sie {}
status.startResolutionForResult (MainActivity.this, 1000);
} catch (IntentSender.SendIntentException e)
{
}
zu brechen;
Fall LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
zu brechen;
}
});
}
GoogleApiClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();