2

My app should find the current location using GPS,Cellular network orWiFi.I can easily find out the current location by GPS

LocationManager locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationlistener = new mylocationlistener();
locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationlistener);

where mylocationlistener()function is like below

private class mylocationlistener implements LocationListener {
  @Override
  public void onLocationChanged(Location location) {
      if (location != null) {
      Toast.makeText(LocationActivity.this,"latitude: "+
          location.getLatitude() + "longitude: " + location.getLongitude(),
          Toast.LENGTH_LONG).show();
      }
  }

It is working properly.I can use celluler network to find out the current location by the above code where i need to change locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationlistener);

it is okey but my challenge is

  1. I need to find the GPS signal strength in order to activate GPS.If GPS signal strength is poor then i can't activate GPS because it will drain battery.
  2. If GPS signal is poor i have to find out the current location by cellular network or WiFi.

So,my question is that if there any way to determine the GPS signal strength without turning on GPS? Thank you advance for any kind of help.

Humayun Kabir
  • 561
  • 2
  • 13
  • 27

1 Answers1

2

No, you cannot determine the signal strength of a sensor that is not turned on.

To determine the strength of a signal between a satellite and a GPS unit such as a phone, the two need to send and receive GPS signals, which naturally requires that GPS on the phone be turned on.

It's the same logic that says you can't list the available nearby WiFi networks without turning on WiFi.

Your best option is to briefly turn it on, then turn it off if you decide not to use it.

The easiest way to determine whether or not to use GPS would be to turn it on, then use the LocationManager's getBestProvider method. If the best provider is NOT GPS, then turn it off again. You can also use the getGpsStatus method to get a GpsStatus object with metrics such as max number of satellites and the time it took to to receive a fix.

See Enable GPS programatically like Tasker for how to enable/disable GPS. Sadly, you can only programmatically do so on pre-2.3 phones, and then only through an exploit. The "correct" way is to prompt the user to enable or disable it.

Community
  • 1
  • 1
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • You may also want to check out Google's [Location Strategies](http://developer.android.com/guide/topics/location/strategies.html) guide, which provides a number of suggestions as to how to do this and minimize the app's impact on the phone's battery. – Bryan Herbst Jul 17 '12 at 02:17
  • Thank you Tanis.7x.Can you help me how can i determine `GPS` signal strength and how can i turn on/off 'GPS'? – Humayun Kabir Jul 17 '12 at 05:10
  • One way to achieve this may be to use something like the Location API provided by the One API Gateway http://oneapi-gw.gsma.com/ that uses a web based API to get location based on the cell. This is only currently available in Canada but is being rolled out elsewhere. It might be a better solution. Some network operators provide access to Location APIs so have a hunt around and see if that helps. – Rod Burns Jul 17 '12 at 09:28