java - BroadcastReceiver 没有像我预期的那样工作
问题描述
我刚刚编写了这个小应用程序,以在每次更改飞行模式时显示一个小的 Toast。它不起作用
package com.example.android.broadcastreceiverexample;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import static android.widget.Toast.*;
public class MyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
makeText(context, "Intent detected", LENGTH_LONG).show();
}
}
这是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.android.broadcastreceiverexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyReceiver" android:exported="true">
<intent-filter tools:ignore="ExtraText">
<action android:name="android.intent.action.AIRPLANE_MODE></action>
</intent-filter>
</receiver>
</application>
</manifest>
这里有什么我在概念上或代码中遗漏的东西吗?
解决方案
推荐阅读
- python - 如何删除由循环制作的按钮
- amazon-cloudwatch - Cloudwatch 代理中的“mem_available”和“mem_free”有什么区别?
- reactjs - Redux:无法使用商店
- google-analytics - 如何在所有环境中处理一个 Google Analytics(分析)标签(DEV/TEST/PROD)
- c# - 有没有办法解除两个对象之间的引用绑定
- design-patterns - 使用存储在 redux 中的状态对可重用的反应组件进行建模
- pandas - 使用多处理优化 groupby-agg 查询
- mysql - Mysql - 如何选择列名包含单元格值的列
- c++ - 使用成员在类中创建 lambda 表达式
- flutter - 在简单应用程序中调用 Navigator.push() 时 _debugLocked 断言失败