I'm a noob to android development and I am trying to figure out how to use the Fused Location Provider. I'm using this tutorial and have no issues implementing as the tutorial shows. However, now I want to get my last location from within an intent service. The problem is that a new instance of Location Client is not accepting context or context.getApplicationContext() as parameters for ConnectionCallbacks and ConnectionFailedListner. GooglePlayServicesClient.ConnectionCallbacks and GooglePlayServicesClient.OnConnectionFailedListener are implemented with their accompanying methods. Any help is greatly appreciated.
MY CODE
public class GCMIntentService extends GCMBaseIntentService implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener{...
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
//Checking for message type
//Received geofence coordinates
if (message.contains("Your parent is acquiring your current location")){
c = context;
//Force get location
locationclient = new LocationClient(c,c,c);//<--Not working
locationclient = new LocationClient(c,c.getApplicationContext(),c.getApplicationContext());//<--Not working
locationrequest = LocationRequest.create();
locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationclient.connect();
}else{...
How Do I Implement LocationClient within Intent Service?
You wouldn't. LocationClient
's API is asynchronous, which does not work well with IntentService
. Use a regular Service
, manage your own background thread as needed, and call stopSelf()
when you no longer need the service.
The problem is that a new instance of Location Client is not accepting context or context.getApplicationContext() as parameters for ConnectionCallbacks and ConnectionFailedListner.
You have to pass in implementations of those listener interfaces.
GooglePlayServicesClient.ConnectionCallbacks and GooglePlayServicesClient.OnConnectionFailedListener are implemented with their accompanying methods
Not on Context
and not on Application
. You did not write those classes -- Google did. You cannot implement those interfaces on those classes as a result.
Somewhere, perhaps, you did implement those interfaces, in which case you need to pass an instance of that object (or objects, plural) to the appropriate methods.