2

up until now, when using the LocationClient in order to obtain the user's last known location, I had no problems, testing on Jelly Bean for example.

I got a KitKat phone to test on, and I found that there is a DEFAULT setting in Settings -> Location, that is called "Device only" and it solely relies on GPS to start, connect and obtain location. This takes A WHILE. Also, when Im indoors it might get no location whatsoever.

If I go to Settings, and switch to "High accuracy" I go back to my app and BAM location is right there.

Question is:

How do I detect which of those three location settings is set on KitKat and ask the user to change it (or directly change it myself)

The three settings are:

-device only

-battery save mode

-high accuracy

shyam
  • 1,348
  • 4
  • 19
  • 37
Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180

1 Answers1

1

As far as I know, you can individually determine which of the services are enabled/disabled using the LocationManager class.

locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

So all you have to do would be to determine which of them are enabled, and act accordingly. If either of them are disabled, you could ask the user to turn them on.

if(!isGPSEnabled) {
    startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
if(!isNetworkEnabled) {
    startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}

EDIT : You could use the LocationManager class to just get your settings right and then use LocationClient to actually gather location information.

shyam
  • 1,348
  • 4
  • 19
  • 37
  • I just stopped using LocationManager class a couple of weeks ago after reading numerous articles about it being the old location API and how LocationClient is much better and the new way to go. And really, after the switch a lot of problems went away. I dont want to go back to using it. – Kaloyan Roussev Nov 01 '14 at 10:42
  • Is that so? I don't know. It sure is not mentioned in the official page: http://developer.android.com/reference/android/location/LocationManager.html :) – shyam Nov 01 '14 at 11:00
  • 1
    Look at this discussion. it looks as if there are pros and cons to both... http://stackoverflow.com/questions/18916273/locationclient-vs-locationmanager perhaps I use a combination of them? – Kaloyan Roussev Nov 01 '14 at 11:06
  • Exactly. You could make use of `LocationManager` just to make sure your settings are proper. Either way, lets see if someone else comes up with something better! – shyam Nov 01 '14 at 11:09
  • 1
    But this .isProviderEnabled(LocationManager.GPS_PROVIDER); will return true for both Device Only and High Accuracy. I need to know exactly which one is being used. – Kaloyan Roussev Nov 01 '14 at 11:12
  • Of course. In both these cases GPS should be enabled. It is disabled only in battery save mode. – shyam Nov 01 '14 at 11:15
  • Yeah but in Device only, the system only relies on GPS and it takes forever to connect. I need to use ONLY High accuracy mode, because it shows my correct location right away. So my question remains how do I detect (if possible) which of these kitkat modes is the phone set to – Kaloyan Roussev Nov 01 '14 at 11:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/64085/discussion-between-shyam-and-j-k). – shyam Nov 01 '14 at 11:22
  • did u find any solution? @J.K. – user232803 Sep 22 '15 at 02:54