Stap 10:
Nu gewoon kopiëren en plakken na code buiten oncreate methode...
privé GoogleApiClient googleApiClient;
Nu enkel exemplaar en deeg volgende code in oncreate...
Als (googleApiClient == null) {}
googleApiClient = nieuwe 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 bouwer = nieuwe LocationSettingsRequest.Builder() .addLocationRequest(locationRequest);
// **************************
builder.setAlwaysShow(true); Dit is het belangrijkste ingrediënt
// **************************
PendingResult resultaat = LocationServices.SettingsApi .checkLocationSettings (googleApiClient, builder.build()), result.setResultCallback (nieuwe ResultCallback)
{
openbare nietige onResult (LocationSettingsResult resultaat)
{
definitieve Status status = result.getStatus();
LocationSettingsStates eindtoestand = resultaat .getLocationSettingsStates();
schakelaar (status.getStatusCode())
{
Case LocationSettingsStatusCodes.SUCCESS:
breken;
Case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Probeer {}
status.startResolutionForResult (MainActivity.this, 1000);
} vangst (IntentSender.SendIntentException e)
{
}
breken;
Case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
breken;
}
});
}
googleApiClient = nieuwe GoogleApiClient.Builder(this).addApi(AppIndex.API).build();