0

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?

Cristian
  • 514
  • 4
  • 21
  • Whats does the binding activity code look like? – LordSquall Apr 02 '14 at 16:04
  • startService(new Intent(this, ServiceBeezer.class)); – Cristian Apr 02 '14 at 16:19
  • Before going any further, the StartService call should return a ComponentName object. Just check to make sure it's not null, otherwise it might be a manifest issue – LordSquall Apr 02 '14 at 16:36
  • startService return a Object, with name "ServiceBeezer" – Cristian Apr 02 '14 at 16:45
  • I think you are missing your binder, Usually you create a local class which extends Binder, this can pass back the reference to this server, currently you return null from your onBind function, Check out this tutorial http://dharmendra4android.blogspot.com/2012/05/bind-service-using-ibinder-class.html it worked for me :) – LordSquall Apr 02 '14 at 16:48
  • sorry i meant to this Service....not server – LordSquall Apr 02 '14 at 16:53
  • [LocationClient](https://developer.android.com/reference/com/google/android/gms/location/LocationClient.html) is deprecated. Look at this answer for current options: [LocationManager or Location Service API](http://stackoverflow.com/questions/24266362/android-google-maps-api-location/27195920#27195920) – MiguelHincapieC Nov 28 '14 at 21:45

1 Answers1

1

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

Revathi
  • 172
  • 8