AlarmManagerIntent 没有被调用
我想使用 AlarmManager 调用 BroadcastReciever:
Context ctx=getApplicationContext();
Intent StartIntent = new Intent(ctx, tartReceiver.class);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC, StartTime.toMillis(false), PendingIntent.getActivity(ctx, 6,
StartIntent, PendingIntent.FLAG_CANCEL_CURRENT ));
接收器在清单中声明如下:
<receiver android:process=":remote" android:name=".StartReceiver" android:exported="true"/>
但什么也没有发生。如果我使用 ctx.sendBroadcast(StartIntent) ,则会调用意图,所以应该没问题,还是不行? 我还检查了 StartTime,应该没问题,我也尝试了 0 (这应该会导致根据文档立即调用 Intent)。
我必须改变什么才能让它工作?
I want to use the AlarmManager to call a BroadcastReciever:
Context ctx=getApplicationContext();
Intent StartIntent = new Intent(ctx, tartReceiver.class);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC, StartTime.toMillis(false), PendingIntent.getActivity(ctx, 6,
StartIntent, PendingIntent.FLAG_CANCEL_CURRENT ));
The receiver is declared in the manifest like this:
<receiver android:process=":remote" android:name=".StartReceiver" android:exported="true"/>
But nothing ever happens. If I use ctx.sendBroadcast(StartIntent), the intend gets called, so it should be all right, or not?
I also checked the StartTime, it should be ok and I tried also 0 (which should cause the Intent to be called immediately according to the documentation).
What must I change to get it working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JonathanK,
您需要
PendingIntent.getBroadcast()
而不是PendingIntent.getActivity()
。JonathanK,
You want
PendingIntent.getBroadcast()
notPendingIntent.getActivity()
.