1

I am making a system app SDK9+ ( has WRITE_SECURE_SETTINGS permissions )

I repeat this is for a close group of people and is a system app

I can turn GPS on but can't turn it off with this code :

public void gpsOn () { //This works
        try {
            Settings.Secure.setLocationProviderEnabled(mContext.getContentResolver(), LocationManager.GPS_PROVIDER, true);
        } catch (Exception e) {
            Log.i(TAG, e.getMessage());
        }
    }


public void gpsOff () { // This doesn't work why?
    try {
        Settings.Secure.setLocationProviderEnabled(mContext.getContentResolver(), LocationManager.GPS_PROVIDER, false);
    } catch (Exception e) {
        Log.i(TAG, e.getMessage());
    }
}

It just fails silently no log/exception what so ever

Muhamed Krlić
  • 1,462
  • 2
  • 16
  • 25
  • first of all, a bit of politeness wouldn't hurt you! and second, if you'll bother reading *all* the answers in the link you'll see that you can't turn off GPS in android - but [*you can prompt the user to do so*](http://stackoverflow.com/questions/1051649/how-to-programmatically-enable-gps-in-android-cupcake) – Nir Alfasi Jul 20 '14 at 03:50
  • I understand your frustration but it doesn't change the facts: since Android 1.5 you cannot turn the GPS off (you *can* turn it on though), in order to turn it off you should prompt the user. That decision was made by the android team and I'm sure that if you'll think about it for a second you'll agree that it's a good design-decision. – Nir Alfasi Jul 20 '14 at 04:30
  • Ohhhh so you really need this option and the user is not who I thought it is, okay - that makes everything different! why didn't you say so earlier ? in that case, there is a solution. But you have to promise that it's going to be used for a closed group of people and also not to tell anyone, cause we don't want it to leak to apps that are not (underlined) "SYSTEM apps". okay ? – Nir Alfasi Jul 20 '14 at 16:50

0 Answers0