Cristian
Cristian

Reputation: 514

Retrieve location from Service

I'm trying to do a service, who listen user's location.

Code bellow:

public class ServiceBeezer extends Service implements
    OnConnectionFailedListener, ConnectionCallbacks {

    private LocationRequest mLocationRequest;
    private LocationClient mLocationClient;

    public ServiceBeezer() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        // 1. init locationrequest
        mLocationRequest = LocationRequest.create();
        mLocationRequest.setInterval(1000);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_NO_POWER);
        mLocationRequest.setFastestInterval(1000);

        // 2. mlocationclient
        mLocationClient = new LocationClient(this, this, this);

        return START_STICKY;
    }

    @Override
    public void onConnected(Bundle arg0) {
        Toast.makeText(this,
                getClass().getSimpleName() + "onConnected: " + arg0,
                Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDisconnected() {
        Toast.makeText(this, getClass().getSimpleName() + "onDisconnected: ",
                Toast.LENGTH_LONG).show();
    }

    @Override
    public void onConnectionFailed(ConnectionResult arg0) {
        Toast.makeText(this,
                getClass().getSimpleName() + "onConnectionFailed: " + arg0,
                Toast.LENGTH_LONG).show();
    }

}

But onConnected(), onDisconnected() and onConnectionFailed() is never called.

What I doing wrong?

I have other LocationRequest, and LocationClient inside on Activity.

Can be this the problem?

Upvotes: 0

Views: 135

Answers (1)

Revathi
Revathi

Reputation: 172

If I am not wrong you haven't called mLocationClient.connect() anywhere in the code you pasted above.

Upvotes: 1

Related Questions