Bekomme kein Intent(LocationClient)

  • 0 Antworten
  • Letztes Antwortdatum
I

Isildur

Fortgeschrittenes Mitglied
1
Hallo,

Hintergrund
ich versuche gerade Location Services mittels LocationClient zu implementieren. Es ist ein dienstliches Projekt und es lief vorher mit LocationManager, das ist aber unschöner in der Handhabung als der GooglePlayService basierte LocationClient.
Ich hatte das ganze nach diesem Tutorial mittels LocationListener zum laufen gebracht. Das funktioniert aber nur im Foreground, wir brauchen aber unbedingt zuverlässige Locationupdates im Background.

Problem
Daher habe ich versucht das ganze mittels PendingIntents zu implementieren, kann aber keine Intents fangen und ich habe keine Ahnung wieso. Hier der Code
Code:
public class DashboardActivity extends Activity implements OnClickListener, OnItemClickListener, CaseListener, OnCheckedChangeListener, OnScrollListener, IRestReceiver,ConnectionCallbacks, OnConnectionFailedListener  {
[....]
    private LocationClient mLocationClient;
    private LocationRequest mLocationRequest;
    private PendingIntent mPendingIntent;
    ParcelableLocation myLocation = null;
    @Override
    public void onCreate( Bundle savedInstanceState ) {
    [...]
            //Location service
        mLocationRequest = LocationRequest.create();
        mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); //PPRIORITY_BALANCED_POWER_ACCURACY for power optimization; PRIORITY_HIGH_ACCURACY Debug
        mLocationRequest.setInterval(UPDATE_INTERVAL);
        mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
        mLocationRequest.setSmallestDisplacement(MIN_DISTANCE);
        mLocationClient = new LocationClient(this.getApplicationContext(), this, this);
        Intent intent = new Intent( this.getApplicationContext(), LocationIntentService.class);
        mPendingIntent = PendingIntent.getService(this.getApplicationContext(), 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
    @Override
    protected void onStart() {
        super.onStart();
        mLocationClient.connect();
    }
    //@Override
    public void onConnected(Bundle dataBundle) {
        Location lastLocation = mLocationClient.getLastLocation();
        if( lastLocation != null ) {
            myLocation = new ParcelableLocation();
            myLocation.setLatitude( lastLocation.getLatitude() );
            myLocation.setLongitude( lastLocation.getLongitude() );
            Base.log("lastLocation:" + lastLocation.getLatitude() +"/"+ lastLocation.getLongitude());
        }else{
            Base.log("no lastLocation found");
        }
        mLocationClient.requestLocationUpdates(mLocationRequest, mPendingIntent);
    }
Code:
public class LocationIntentService  extends IntentService {
    
    public LocationIntentService(String name) {
        super("LocationIntentService");
    }
    public void onCreate(){
        super.onCreate();
        Base.log("Intent onCreat()");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Base.log("caught an intent");
        //need some logic for getting the position from the intent
    }
}
Bin für jeden Hinweis dankbar, habe da nun schon lange dran gearbeitet aber keine Lösung gefunden und es gibt kaum Beispielcode dazu.

Vielen Dank schonmal!

Edit:Grund war, dass bei der Definition des Services im Manifest der Pfad nicht korrekt war.
 
Zuletzt bearbeitet:
Zurück
Oben Unten