广播未通过AlarmManager呼叫

时间:2019-05-06 11:29:26

标签: android broadcastreceiver alarmmanager

警报管理器应发送的广播消息有问题。 这是我的代码:

case Intent.ACTION_BOOT_COMPLETED:
                long repeatInterval = 10*1000;
                long triggerTime = SystemClock.elapsedRealtime() + repeatInterval;
                AlarmManager manager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
                if(manager != null){
                    Intent in = new Intent(context, AppReceiver.class);
                    in.setAction("haz");
                    PendingIntent inte = PendingIntent.getBroadcast(context, 500, in, PendingIntent.FLAG_UPDATE_CURRENT);



                    manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerTime, repeatInterval, inte);
                }
                break;

动作启动已完成的广播消息已正确触发了该消息,但是如果我没错,那段代码应使用“ haz”动作调用应用接收器,但始终不会被调用。 我试图创建服务,但也没有被调用。

有人知道我该做什么吗?

2 个答案:

答案 0 :(得分:0)

 <receiver android:name=".YourReceiver">
    <intent-filter android:priority="1000">
       <action android:name="android.intent.action.BOOT_COMPLETED" />
       <!-- check properly boot intent syntax for manifest file -->
    </intent-filter>
 </receiver>

答案 1 :(得分:0)

感谢CommonsWare回答了我的问题,我找到了解决方案。答案是要分别设置另一个接收器,可能是因为android无法处理快速重复。我的最终结果不会那么短,它只是为了测试,但是有两个接收器,并通过重复调用第二个接收器才是答案。感谢@CommonsWare和@Arwy Shelke的时间和答复!