Android requestLocationUpdates using PendingIntent with BroadcastReceiver
<p>How do I use </p>

<pre><code>requestLocationUpdates(long minTime, float minDistance, Criteria criteria,
                                                           PendingIntent intent) 
</code></pre>

<p>In BroadcastReciver so that I can keep getting GPS coordinates. </p>

<p>Do I have to create a separate class for the LocationListener ?</p>

<p>Goal of my project is when I receive <code>BOOT_COMPLETED</code> to start getting GPS lats and longs periodically.</p>

<p>Code I tried is :</p>

<pre><code>public class MobileViaNetReceiver extends BroadcastReceiver {

    LocationManager locmgr = null;
    String android_id;
    DbAdapter_GPS db;

    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            startGPS(context);
        } else {
            Log.i("MobileViaNetReceiver", "Received unexpected intent "
                + intent.toString());
        }
    }

    public void startGPS(Context context) {
        Toast.makeText(context, "Waiting for location...", Toast.LENGTH_SHORT)
                .show();
        db = new DbAdapter_GPS(context);
        db.open();
        android_id = Secure.getString(context.getContentResolver(),
                Secure.ANDROID_ID);
        Log.i("MobileViaNetReceiver", "Android id is _ _ _ _ _ _" + android_id);
        locmgr = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5,
                onLocationChange);
    }

    LocationListener onLocationChange = new LocationListener() {

        public void onLocationChanged(Location loc) {
            // sets and displays the lat/long when a location is provided
            Log.i("MobileViaNetReceiver", "In onLocationChanged .....");
            String latlong = "Lat: " + loc.getLatitude() + " Long: "
                + loc.getLongitude();
            // Toast.makeText(this, latlong, Toast.LENGTH_SHORT).show();
            Log.i("MobileViaNetReceiver", latlong);
            try {
                db.insertGPSCoordinates(android_id,
                        Double.toString(loc.getLatitude()),
                        Double.toString(loc.getLongitude()));
            } catch (Exception e) {
                Log.i("MobileViaNetReceiver",
                        "db error catch _ _ _ _ " + e.getMessage());
            }
        }

        public void onProviderDisabled(String provider) {}

        public void onProviderEnabled(String provider) {}

        public void onStatusChanged(String provider, int status, Bundle extras) {}
    };    
    //pauses listener while app is inactive
    /*@Override
    public void onPause() {
        super.onPause();
        locmgr.removeUpdates(onLocationChange);
    }

    //reactivates listener when app is resumed
    @Override
    public void onResume() {
        super.onResume();
        locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, onLocationChange);
     }*/
}
</code></pre>
