0

Possible Duplicate:
Broadcast reciever for GPS state?

Is there a listener that can notify me when GPS is activated? (When user enabled "GPS" button from the notification bar)
I tried using addGpsStatusListener but it is not what I was looking for.

Community
  • 1
  • 1
Rami
  • 2,098
  • 5
  • 25
  • 37

2 Answers2

1

Ok dude, sorry my bad, now I know what you mean, your question is answered here :) Detecting GPS on/off switch in Android phones The only problem is that it only works on API Level 9 and above. I hope this answer your question.

Stay cool, Stay awesome.

Good Luck

Community
  • 1
  • 1
Zardaloop
  • 1,594
  • 5
  • 22
  • 43
  • Dude I googled it.. and dude I saw this answer and it is not solving my problem. I know how check if the GPS is on/off. I want to get notified when there is a change. – Rami Jul 12 '12 at 16:03
  • sorry dude my bad, I have edited my answer, I hope that help you..Let me know if it answered your question. Good Luck :) – Zardaloop Jul 13 '12 at 00:23
  • Thanks man, It is working good. I guess my question is dup after all, And I need to try google better next time :) – Rami Jul 13 '12 at 11:51
0

You have to implement LocationListener interface and use the onProviderEnabled method.

Dmytro Titov
  • 2,802
  • 6
  • 38
  • 60
  • I want to get notified when there is a change, not to check by myselef. – Rami Jul 12 '12 at 16:06
  • So that is exactly what you need. You don't have to check anything. All you have to do is to implement LocationListener. When the GPS (or another geolocation provider) will be turned on, the method onProviderEnabled will be raised. – Dmytro Titov Jul 12 '12 at 16:10
  • If the GPS_PROVIDER is set in the LocationListener you are true, and onProviderDisabled and onProviderEnabled will work. But if NETWORK_PROVIDER is set it will not work. I have already tried it. – Rami Jul 12 '12 at 16:17
  • Well, you can simply create another instance of LocationManager, linked to GPS provider. – Dmytro Titov Jul 12 '12 at 16:23
  • I can but just one provider can be attached to requestLocationUpdates. So I can't see how it will work, but thanks. – Rami Jul 12 '12 at 16:29
  • By the way, you didn't mention why addGpsStatusListener() is not the option for you? – Dmytro Titov Jul 12 '12 at 16:33
  • Because it notifies when starts , stops , and searching not when GPS activated from settings or notification bar. – Rami Jul 12 '12 at 16:37