1

I need to hide the GPS icon from the status bar when my service disabled.

In my application I have two menu options, when I press the "enable" then the gps icon has to display on status bar and when I press the "disable" then the gps icon should not display on the status bar.

Reno
  • 33,594
  • 11
  • 89
  • 102
  • Thank u. Already I did this but I don't want to disable the gps through settings.I want to disable it through programming when I press the "disable" menu item. –  May 23 '12 at 05:31
  • If what you're asking is how to hide the GPS icon when GPS is actually still active, then no -- you can't do that. Nor should you. –  May 23 '12 at 05:43

4 Answers4

2

If you are requesting for GPS updates through the LocationManager, you can use this function to remove the updates (disable GPS):

locationManager.removeUpdates(this);
Hesham Saeed
  • 5,358
  • 7
  • 37
  • 57
1

To hide the GPS icon when service is stop you need to remove registration for location updates of the current activity.

You can do this by calling the removeUpdates(PendingIntent intent) on location manager.

removeUpdates(PendingIntent intent)
Removes any current registration for location updates of the current activity with the given PendingIntent.

check out this Link

Kri
  • 1,846
  • 2
  • 13
  • 17
0

Simply you gonna have to disable the GPS device. When you disable GPS, icon will dissapear from the system tray.

Check this question for the answer.

Community
  • 1
  • 1
Jay Mayu
  • 17,023
  • 32
  • 114
  • 148
  • Can I write the code like this in service class's onDestroy method –  May 23 '12 at 09:53
  • like public void onDestroy() { super.onDestroy(); mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mlocListener = new MyLocationListener(); ((LocationManager) mlocListener).removeUpdates((LocationListener) this); Log.v("destroy","destroy"); Intent it=new Intent(NewThread.this,LanLatActivity.class); startActivity(it); flag=false; } –  May 23 '12 at 09:56
  • to stop GPS and show the home page of application( LanLatActivity). Here the application terminates when I click "Disable" menu item. Pls help me. Its some urgent task for me. –  May 23 '12 at 09:56
  • In another way also I tried. the below code public void onDestroy() { super.onDestroy(); ((LocationManager) mlocListener).removeUpdates((LocationListener) this); flag=false; –  May 23 '12 at 10:11
0

Simple. When you want the icon, enable GPS, and when you don't want it, disable GPS.

nithinreddy
  • 6,167
  • 4
  • 38
  • 44
  • thank you very much. If I have any doubt I will ask u because I am new to this technology. I am working on this from 2 weeks. –  May 23 '12 at 05:59