Broadcast receiver with AIRPLANE_MODE not working with SDK 26

最后都变了- 提交于 2019-12-23 19:13:26

问题


Normaly, I use a simple code to put a Toast when the user change the AIRPLANE_MODE, and it work using targetSdkVersion 25.

My AirPlaneModeReceiver :

    public class AirPlaneModeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Toast.makeText(context, "I receive a Broadcast", Toast.LENGTH_SHORT).show();

    }
}

The part of the Manifest where I declare my Receiver :

<receiver android:name=".AirPlaneModeReceiver">
            <intent-filter>
                <action android:name="android.intent.action.AIRPLANE_MODE"/>
            </intent-filter>
</receiver>

But when I change the target SDK version to targetSdkVersion 26, it's not working at all... Why ?


回答1:


As per documentation:

you should remove any broadcast receivers that are registered for implicit broadcast intents.

https://developer.android.com/about/versions/oreo/android-8.0-migration.html

see Section "Remove broadcast receivers from your manifest file"



来源:https://stackoverflow.com/questions/44919613/broadcast-receiver-with-airplane-mode-not-working-with-sdk-26

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!