android - GPS OnPause code does not turn off the GPS -


  @ Override Protected Zero at Pause () {If (Lm! = Null) {lm.removeUpdates (ll); } Ll = null; Lm = null; Super.onPause (); }   

This code will run without any errors, as long as the LM and we are declared globally protected variables. The problem is that after leaving the program the GPS icon remains. How can I turn off GPS? I tested it on a phone and emulator.

As the doctor says about:

given Removes any existing registration to update the location of the current activity from the place list.

Your current code only removes any existing registration given for the location updates of the current activity. Placement GPS is not stopped or remove the mark from the status bar. So if you want to turn off GPS, then you have two solutions

First solution: by code (only work on Android 2.3):

 Try  {string provider = settings. Safe. Gate string (getContentResolver (), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); If (! Provider.contains ("GPS")) {Last Intention Poke = New Intention (); Poke.setClassName ("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); Poke.addCategory (Intent.CATEGORY_ALTERNATIVE); Poke.setData (Uri.parse ("3"); SendBroadcast (strike); }} Hold (exception e) {log d. ("Location", "Exceptions thrown in to enable GPS" + E); }   

Permission in Manifest.xml:

  android.permission.WRITE_SECURE_SETTINGS   

Second Solution: Launch GPS Settings:

  startActivityForResult (new intent (settings.Oction_OLACNCOSSTNSS), 1);    

Comments