Wie können Standort-Updates direkt an Intent Service gesendet werden? Der folgende Ansatz funktioniert nicht. OnConnected Funktion wird aufgerufen, aber dann ist es die Absicht, nie in den Dienst erhalten:Standort-Updates an IntentService senden
...
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);
}
...
Intent Service:
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-Datei:
...
<service android:name=".LocationUpdateService" />
...
, wenn Sie sind auf dem Emulator Sie diesen Link gesetzt Geolocation sehen maually haben: http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator hast du m_googleApiClient.connect() ?? – kamokaze