问题描述
通常,我使用简单的代码在用户更改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一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!