android - 我的 BroadcastReceiver 有问题,设备重启后没有调用接收器
问题描述
我的程序从 BroadCastReciever 扩展以设置警报,设备重启后不调用接收器,这是我的代码
1-广播接收器
public class myReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction()!=null) {
if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")) {
Log.d("myActivity","repooted");
// alarm settings
}
}
}
2-xml
<receiver
android:name=".sync.myReceiver"
android:enabled="true"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>
</receiver>
解决方案
在您的 AndroidManifest.xml 中,您是否添加了接收启动完成的权限?
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
推荐阅读
- bash - .gz 文件日志中 txt 列表中的大 grep
- angularjs - 意外请求:GET 后跟 [$rootScope:inprog] $digest 已经在进行中。Angularjs 和 Karma
- r - 识别、分组数据框 (R) 中的唯一条目
- python - 两个 AEM 环境中的节点权限比较
- c# - logging.AddAzureWebAppDiagnostics() 在 .net core 2.2 中不起作用
- go - 如何从 Go 中的 http 客户端获取 x509 证书
- php - SQL:获取SUM中属于不同值的正确ID
- javascript - 单击时未删除 eventListener
- python - 字典中列表的嵌套循环
- python - 使用 python 和 pandas 从一个非常大的文本文件中提取数据?