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 ;)