Why is my BroadCast Receiver not working?

前端 未结 6 928
礼貌的吻别
礼貌的吻别 2021-01-21 16:03

I am learning about BroadCast Receivers. What I am trying to achieve with the following piece of code is, I would like to see a toast when I switch to airplane mode, where the a

6条回答
  •  走了就别回头了
    2021-01-21 17:00

    From the android documentation :

    https://developer.android.com/guide/components/broadcast-exceptions

    As part of the Android 8.0 (API level 26) Background Execution Limits, apps that target the API level 26 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest. However, several broadcasts are currently exempted from these limitations. Apps can continue to register listeners for the following broadcasts, no matter what API level the apps target.

    and

    https://developer.android.com/distribute/best-practices/develop/target-sdk

    Google Play will require that new apps target at least Android 8.0 (API level 26) from August 1, 2018, and that app updates target Android 8.0 from November 1, 2018.

    "android.intent.action.AIRPLANE_MODE" is no longer in the list of exempted broadcasts. So, register your broadcast receiver in activity rather than in AndroidManifest.

提交回复
热议问题