Android: detect when GPS is turned on/off (or when no app is using it anymore)

前端 未结 4 1495
太阳男子
太阳男子 2021-02-13 02:24

I\'m on Android 2.3.7 and I\'m trying to write a BroadcastReceiver that will get called when the user turns GPS on/off (ie: by tapping on the \"use GPS satellites\" in the optio

4条回答
  •  眼角桃花
    2021-02-13 02:39

    On API level 9 and higher you can use LocationManager.PROVIDERS_CHANGED_ACTION:

    Broadcast intent action when the configured location providers change. For use with isProviderEnabled(String). If you're interacting with the LOCATION_MODE API, use MODE_CHANGED_ACTION instead.

    Constant Value: "android.location.PROVIDERS_CHANGED"

    Source

提交回复
热议问题