In che modo gli aggiornamenti di posizione possono essere inviati direttamente a Intent Service? Il seguente approccio non funziona. Funzione OnConnected viene chiamata, ma poi l'intento non è mai ricevuto nel servizio:Invia aggiornamenti posizione a IntentService
...
private PendingIntent getLocationPendingIntent(boolean shouldCreate) {
Intent broadcast = new Intent(m_context,LocationUpdateService.class);
int flags = shouldCreate ? 0 : PendingIntent.FLAG_NO_CREATE;
return PendingIntent.getService(m_context, 0, broadcast, flags);
}
@Override
public void onConnected(Bundle arg0) {
PendingIntent locationPendingIntent = getLocationPendingIntent(true);
LocationRequest locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(LOCATION_UPDATE_INTERVAL);
locationRequest.setFastestInterval(LOCATION_FASTEST_UPDATE_INTERVAL);
LocationServices.FusedLocationApi.requestLocationUpdates(m_googleApiClient, locationRequest,locationPendingIntent);
}
...
Servizio Intent:
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
public class LocationUpdateService extends IntentService {
public LocationUpdateService() {
super(LocationUpdateService.class.getName());
}
@Override
public int onStartCommand(Intent intent, int flags, int startID) {
super.onStartCommand(intent, flags, startID);
Log.d("LocationUpdateService","Location received");
return START_REDELIVER_INTENT;
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("LocationUpdateService","Intent received");
}
}
manifest: metodo
...
<service android:name=".LocationUpdateService" />
...
quando si sono sull'emulatore è necessario impostare maually geolocalizzazione vedere questo link: http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator hai chiamato m_googleApiClient.connect() ?? – kamokaze