I have started to implement the Google Location API using this tutorial.
I've managed to get it to work in my application quite fine, it updates my location at the right intervals etc. Now I am working on how to update my location when the device is in sleep mode. According to the documentation, this method is the way to go:
public void requestLocationUpdates (LocationRequest request, PendingIntent callbackIntent);
My question is, how do I set up this PendingIntent, and how do I handle it? I've seen tutorials of how to handle other types of intent, but I am not sure how to apply them to this.
You can either register Broardcast Reciever or Activity through pending intent.Sample Example for registering boardcast reciever:
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 Reciever:
public class ProximityIntentReceiver extends BroadcastReceiver {
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context arg0, Intent intent) {
//action to be performed
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With