Google location APIs: request location updates with pending intent?

I started implementing the Google Location API using this tutorial .

I managed to get it to work very well in my application, it updates my location at the right intervals, etc. Now I am working on updating my location when the device is in sleep mode. According to the documentation , this way is the way:

public void requestLocationUpdates (LocationRequest request, PendingIntent callbackIntent); 

My question is, how do I configure this PendingIntent and how to handle it? I have seen tutorials on how to handle other types of intentions, but I'm not sure how to apply them to this.

+8
android google-api location android-pendingintent location-client
source share
1 answer

You can either register a Broardcast receiver or activity through a pending intent. Example Example of registering an airborne receiver:

  String proximitys = "ACTION"; IntentFilter filter = new IntentFilter(proximitys); registerReceiver(mybroadcast, filter); Intent intent = new Intent(proximitys); PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); locationManager.requestLocationUpdates(provider, mintime, mindistance, proximityIntent); 

Your Broardcast Receiver:

 public class ProximityIntentReceiver extends BroadcastReceiver { @SuppressWarnings("deprecation") @Override public void onReceive(Context arg0, Intent intent) { //action to be performed } 
+4
source share

All Articles