0

I need to show the GPS icon on status bar, whenever I call the get lat long function.

But now, the gps icon is shown in through out the application.

How to show/hide the GPS icon in status bar?

Lavanya
  • 621
  • 4
  • 15
  • 28

2 Answers2

3

No, it's not possible to do it with the public API.

To do this, not only will you need a rooted phone,but you will need to modify services.jar (and perhaps framework.jar also) in order to be able to hide this. In short, unless you're compiling your own version of the Android ROM, you can't really do this.

Alternatively, as suggested by Someone Somewhere, you can hide the status bar altogether.

However, if you want to make sure the GPS icon isn't shown when you aren't using it, then is means that you haven't called removeUpdates(), and hence the system is letting the user know that their location is being monitored by an app. To remove the icon, simply call removeUpdates() on the LocationManager.

Community
  • 1
  • 1
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • I think the question is that GPS icon is shown throughout the application. This means OP forgot to call `removeUpdates()` – Reno Feb 23 '13 at 10:32
  • @Reno I dunno. Question isn't really clear on that. I'll add an edit in any case. Thanks for the tip :) – Raghav Sood Feb 23 '13 at 10:54
  • it give me error LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.removeUpdates(this); this cannot be resolved. I implements LocationListener – Mark Thien Dec 30 '14 at 14:03
0

If you are willing to fetch the GPS data in only one screen you can remove/unregister Listener in onPause() that will remove the GPS icon in the status bar. Also, you can register the Listener again inside onResume() to get the GPS icon back when you switch to the same screen/activity again.

You can check this example how it is done.

Also, its always a good thing to unregister the LocationListener when you are done with the GPS work as it can drain the battery too quickly which users don't like at all.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242