首页 > 解决方案 > 我的 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>

标签: androidandroid-broadcast

解决方案


在您的 AndroidManifest.xml 中,您是否添加了接收启动完成的权限?

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

推荐阅读