2

I have used Android SDK Location Manager to get the user location.

I am requesting the location information by using Pending Intent. I have used pending intent because my need to send the location information even the app is not running.

Intent mLocationIntent = new Intent(mContext,
            LocationIntentService.class);
mLocationUpdatePendingIntent = PendingIntent.getService(mContext, 1,
            mLocationIntent, 0);
mLocationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0,
                mLocationUpdatePendingIntent);

Once registered with the above code I am getting the location information at onHandleIntent of LocationIntentService class.

But I don't have the onProviderEnabled or onProviderDisabled method to listen for the gps and network provider status. And also I dont want to use the fused location api.

How can I achieve both of these by requesting the location update using Pending Intent. Or else any other way to register for location information and also for the location provider status.

M Vignesh
  • 1,586
  • 2
  • 18
  • 55

1 Answers1

-1

why don't you use your locationlistener instead an intent?

something like this:

LocationListener mLocationListener = new LocationListener() {

                @Override
                public void onStatusChanged(String provider, int status,
                        Bundle extras) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProviderEnabled(String provider) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onProviderDisabled(String provider) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onLocationChanged(Location location) {
                    // TODO Auto-generated method stub                  

                }
};

Then to do an update use:

LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER))    
                    manager.requestSingleUpdate(LocationManager.GPS_PROVIDER, mLocationListener, null);
AuTi
  • 69
  • 2
  • 8