AIRPLANE_MODE的广播接收器无法与SDK 26一起使用 [英] Broadcast receiver with AIRPLANE_MODE not working with SDK 26

查看:152
本文介绍了AIRPLANE_MODE的广播接收器无法与SDK 26一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我使用简单的代码在用户更改AIRPLANE_MODE时放置Toast,并且可以使用targetSdkVersion 25来工作.

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

我的AirPlaneModeReceiver:

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>

但是当我将目标SDK版本更改为targetSdkVersion 26时,它根本无法工作... 为什么?

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

推荐答案

根据文档:

您应该删除为隐式广播意图注册的所有广播接收器.

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"

这篇关于AIRPLANE_MODE的广播接收器无法与SDK 26一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆