GPS OnPause code does not disable GPS

The GPS will not stop even after I set the OnPause code to stop the GPS service. Here is my code.

    @Override
    protected void onPause() {
        if(lm != null) {
            lm.removeUpdates(ll);
        }
        ll = null;
        lm = null;
        super.onPause();
    }

This code works without errors while lm and ll are declared as protected variables globally. The problem is that the GPS icon remains on after I left the program. How to disable GPS? I checked it on the phone and the emulator.

+5
source share
3 answers

, , , . YouTube, , . , GPS , . , GPS , , .

. lm.removeUpdate(ll);

+1

doc removeUpdates (ListListener listener):

LocationListener.

LocationListener, STOP GPS statusbar.so GPS,

: ( Android 2.3):

  try{
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(!provider.contains("gps")){
         final Intent poke = new Intent();
         poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
         poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
         poke.setData(Uri.parse("3")); 
         sendBroadcast(poke);
     }
     }
     catch(Exception e)
     {
      Log.d("Location", " exception thrown in enabling GPS "+e);
     }

Manifest.xml:

android.permission.WRITE_SECURE_SETTINGS

: Gps. :

startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
+1

Use this in your onPause ()

protected void onPause() 
{
    super.onPause();
    mylocaationoverlay.disableCompass();
    removeLocationUpdates();
}

This will be your removeLocationUpdates ()

public void removeLocationUpdates()
{
    if(locationManager_ != null && myLocationListener_ != null)
        locationManager_.removeUpdates(myLocationListener_);
}

Or try: onPause to stop the LocationManager

0
source

All Articles