java - Boot_Completed 广播未在应用程序中接收
问题描述
我正在测试一个非常基本的应用程序,用于Boot_Completed
在设备重启时进行广播。我正在测试应用程序android 10 OPPO device
以下是我的代码
清单.xml
<receiver android:name=".SampleBootReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<!--For HTC devices-->
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
SampleBootReceiver.java
public class SampleBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("MyApp", " Boot completed fired");
Toast.makeText(context, "fired " , Toast.LENGTH_LONG).show();
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
Log.e("MyApp", "matches intent");
}
}
}
我的应用程序在设备重启时没有收到Boot_Completed
广播。
注意- 如果我在设备重新启动后手动启动应用程序,那么我会在我的应用程序中广播并且能够在 logcat 中看到日志。但是当我在设备重启后没有启动应用程序时,logcat 中没有任何内容。
我什至尝试过showing toast
接收广播,没有任何反应。
请建议!
解决方案
推荐阅读
- ios - 选择器控件绑定到索引而不是标记
- r - R - 当时间列中已经包含当前系统日期时合并数据和时间
- r - 如何正确使用 tryCatch() 并忽略此 rvest 函数中的 404 错误?
- c++ - 排名时指针类型的恒等转换是否视为资格转换
- python - Python 彩票程序 - 如何比较随机列表?
- visual-studio-code - 我可以从 vscode task.json 的删除双引号中保存吗?
- javascript - 任何人都可以协助处理与 discord.js 相关的似乎无法正常工作的代码吗?
- javascript - socket.rooms 值在“断开”侦听器完成之前更改
- python - 气流 mysql_hook 没有名为“MySQLdb”的模块
- python - 按类计算以大写单词开头的行数