0

I have written the below code for getting the best provider available.

private static String provider;

    public static String setCriteria(LocationManager locationManager) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
        provider = locationManager.getBestProvider(criteria, true);
        LocationProvider locProvide = locationManager.getProvider(provider);        
        if (provider == null) {
            provider = LocationManager.GPS_PROVIDER;
        }
        return provider;
    }

I am having this code to find the Provider which i will be using to get the Location. Now what i wish to check is that the status of the Provider. I read from doc that LocationProvider has 3states Available, Out of service & TEMPORARILY_UNAVAILABLE. Now i before requesting to location listener i need to check the status.

If the status is for e.g TEMPORARILY_UNAVAILABLE or Out of Service then user will get the message accordingly else it will find the location. So my question how can i check the status?

If anyone has any idea please kindly help me...

Prem
  • 1,664
  • 3
  • 15
  • 20

2 Answers2

0

You can Try using requestlocationupdates on your Locationmanager object and implement your Locationlistener object... like this..

   LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(provider, 0, 0, ll);

    private class mylocationlistener implements LocationListener {
  ....

    @Override
public void onStatusChanged(String provider, int status, Bundle extras) {
  switch(status){
   case 0:
   //OutofService
     break;
   case 1:
    //Temporarily unavailable
   break;
   case 2:
  //Available
    break;

  }
}
5hssba
  • 8,079
  • 2
  • 33
  • 35
  • I tried the code that you have given. What i did is simply toast messages but nothing is happening. Can you tell me when onStatusChanged will be triggered? – Prem Apr 14 '12 at 10:55
0

AFAIK , this is the ultimate solution for the above mentioned problem..and nothing can go beyond this You just can tell isAvailable or not using the boolean variable isGPSfix

Though you can do other try like this but that are not to guarranty to be work in all situation.

Community
  • 1
  • 1
MKJParekh
  • 34,073
  • 11
  • 87
  • 98