Kullanıcıların konumunu her birkaç dakikada bir arka planda güncellemek istiyorum.
Ben Service
Arka planda konumu güncelleyin ve LocationSettings'i denetleyin
public class MyService extends Service implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener, ResultCallback<LocationSettingsResult>
ile kullanmak için bu örnek kod googlesamples/android-play-location
ama bunu değiştirmesini kullanılan ancak bu yöntem bir Activity
gerektirdiğinden ben konum ayarlarınınprotected void checkLocationSettings() { PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings( mGoogleApiClient, mLocationSettingsRequest ); result.setResultCallback(this); } @Override public void onResult(LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: Log.i(TAG, "All location settings are satisfied."); startLocationUpdates(); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" + "upgrade location settings "); try { // Show the dialog by calling startResolutionForResult(), and check the result // in onActivityResult(). status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { Log.i(TAG, "PendingIntent unable to execute request."); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " + "not created."); break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { // Check for the integer request code originally supplied to startResolutionForResult(). case REQUEST_CHECK_SETTINGS: switch (resultCode) { case Activity.RESULT_OK: Log.i(TAG, "User agreed to make required location settings changes."); startLocationUpdates(); break; case Activity.RESULT_CANCELED: Log.i(TAG, "User chose not to make required location settings changes."); break; } break; } }
kontrol edemez
status.startResolutionForResult (MainActivity.this, REQUEST_CHECK_SETTINGS);
ve MainActvity önceki kod koymak, ben mGoogleApiClient ve mLocationSettingsRequest
LocationServices.SettingsApi.checkLocationSettings (mGoogleApiClient, mLocationSettingsRequest) referanslar değildir;
Etkinlik yok olsa bile arka planı yükseltmek ve kaydetmek isterim.
Hizmeti kullanmanın doğru yolu bu mu?
Konum ayarlarını nasıl kontrol ederim?
[DÜZ]
I PendingIntent
kullanmak güvenilir ve uygulama olsa bile, bir IntentService
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, mPendingIntent);
Bu yöntem, daha özel olarak konum güncellemeleri alınması için, arka plan kullanım durumları için uygundur, Sistem tarafından öldürüldü.
fark Service
ve LocationListner
ile sürümüne göre nedir?
LocationListener'ı kullandım ve FusedLocationAPI çok iyi çalışıyor.Sorunum checkLocationSettings ile. –