Geolocation - New Location API Android. Error quotCall connect and wait for onConnected to be calledquot

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I need your precious help ;)

https://developer.android.com/training/location/index.html https://developer.android.com/training/location/index.html

public class NewLocationPollerService extends Service implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener
{
    private LocationRequest mLocationRequest    = null;
    private LocationClient  mLocationClient     = null;

    ...
    private class PollerThread extends WakefulThread
    {
        protected void onPreExecute()
        {
            if ( GooglePlayServicesUtility.areServicesConnected( NewLocationPollerService.this ) )
                mLocationClient.requestLocationUpdates(mLocationRequest, intent);
        }

        protected void onPostExecute()
        {
            if ( GooglePlayServicesUtility.areServicesConnected( NewLocationPollerService.this ) )
                mLocationClient.removeLocationUpdates(intent);

            super.onPostExecute();
        }
    }
    ...
}

The method " areServicesConnected() " is the following:

public class GooglePlayServicesUtility
{
    private static final String TAG = GooglePlayServicesUtility.class.getSimpleName();

    public static boolean areServicesConnected(Context context)
    {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        if (ConnectionResult.SUCCESS == resultCode)
            return true;
        else
            return false;
    }
    ...
}

Sometimes the service crash and the log is the following:

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
at com.google.android.gms.internal.k.B(Unknown Source)
at com.google.android.gms.internal.bh.a(Unknown Source)
at com.google.android.gms.internal.bh$c.B(Unknown Source)
at com.google.android.gms.internal.bg.requestLocationUpdates(Unknown Source)
at com.google.android.gms.internal.bh.requestLocationUpdates(Unknown Source)
at com.google.android.gms.location.LocationClient.requestLocationUpdates(Unknown Source)
at     me.app.location.NewLocationPollerService$PollerThread.onPreExecute(NewLocationPollerService.java:210    )
at me.app.thread.WakefulThread.onLooperPrepared(WakefulThread.java:79)
at android.os.HandlerThread.run(HandlerThread.java:59)
at me.app.thread.WakefulThread.run(WakefulThread.java:94)

http://stackoverflow.com/questions/17056104/gamesclient-not-connecting-error-call-connect-and-wait-for-onconnected-to http://stackoverflow.com/questions/17056104/gamesclient-not-connecting-error-call-connect-and-wait-for-onconnected-to

Thanks, every help will be really appreciated!

Happy coding ;)

Answers

isGooglePlayServicesAvailable does not tell you that you are connected, it just checks the availability of the service.

You should do exactly what s in your logcat. Call LocationClient.connect() and you ll be connected once your code reaches your implementation of ConnectionCallbacks.onConnected which I don t see in your question.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/19125368/new-location-api-android-error-call-connect-and-wait-for-onconnected-to-be

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils