Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google location API: request location updates with pending intent?

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.

like image 831
HigiPha Avatar asked Jul 24 '13 06:07

HigiPha


1 Answers

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
    }
like image 156
Srikanth Roopa Avatar answered Sep 28 '22 11:09

Srikanth Roopa