在广播接收器中启动警报并在服务中关闭

时间:2011-12-09 22:04:16

标签: android service alarmmanager android-pendingintent

我认为我有设计问题,但我会问你们这个问题。 我的应用程序在xbroadcastreceiver中接收广播,我检查一些条件,如果是,我启动服务,比如zservice,使用带有PendingIntent的Alarm Manager。现在在zservice中,每当它被alarmmanager触发时,我检查一些其他条件并根据我需要取消警报的特定条件,我知道alarmManager.cancel(pendingIntent); 将取消alram,但我的问题是如何访问pendingIntent,就像在xbroadcastreciever中一样。

我已尝试将pendingIntent发送到服务但到目前为止我没有成功,所以当我需要时,我可以关闭闹钟。 希望这个逻辑有意义......

1 个答案:

答案 0 :(得分:0)

  

我知道alarmManager.cancel(pendingIntent);将取消alram,但我的问题是如何访问pendingIntent,就像在xbroadcastreciever中一样。

使用与原始路由信息相同的路由信息​​(组件,操作,类别,MIME类型)创建Intent。从此PendingIntent创建与之前相同类型的Intent(例如getService())。将PendingIntentcancel()电话一起使用。

相关问题