简体   繁体   English

使用AlarmManager调用广播

[英]Broadcast not getting called with AlarmManager

I'm having trouble with the broadcast message the alarm manager should send. 我遇到了警报管理器应该发送的广播消息的问题。 This is my code: 这是我的代码:

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;

That's being triggered correctly with the action boot completed broadcast message, but that piece of code if I'm right should call the app receiver with the "haz" action, but that's not being called, ever. 这是通过动作启动完成的广播消息正确触发,但是如果我是正确的那段代码应该使用“haz”动作调用app接收器,但是这不会被调用。 I've tried to create a service but that's also not being called. 我试图创建一个服务,但也没有被调用。

Anyone has any clue for what I have to do? 任何人都有任何线索我必须做​​什么?

 <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>

I've found a solution thanks to CommonsWare reply to my question. 由于CommonsWare回复了我的问题,我找到了一个解决方案。 The answer was to have another receiver separately probably because android can't handle fast repetitions. 答案是分别有另一个接收器可能是因为android无法处理快速重复。 Mine wasn't going to be that short in the end, it was for testing purposes only, but having two receivers and to call the second one with the repetitions was the answer. 我最终不会那么短,它仅用于测试目的,但是有两个接收器并且重复呼叫第二个接收器就是答案。 Thank you both @CommonsWare and @Arwy Shelke for your time and responses!! 感谢@CommonsWare和@Arwy Shelke的时间和回复!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM