我的程序从BroadCastReciever扩展为设置Alarm,在设备重启后未调用接收器,这是我的代码
1- BroadcastReceiver
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"/>