带有Manifest声明的唯一PendingIntent



我正在创建一个Android应用程序,该应用程序以编程方式创建在应用程序关闭时持续存在的警报。为了让警报持续存在,我必须在Manifest中定义接收器,如下所示:

<receiver
android:name="com.blah.blah.AlarmReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999" >
     <action android:name="com.blah.blah.ALARM" />
</intent-filter>
</receiver>

这是我目前如何创建pendingintent .

Intent intent = new Intent(ACTION_ALARM);
PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager manager = (AlarmManager   (this.getSystemService(Context.ALARM_SERVICE ));

因为我使用恒定的ACTION_ALARM,所有的警报都连接到相同的PendingIntent,所以调用.cancel()删除所有的警报。但是,我想删除特定的告警实例。我所知道的创建唯一PendingIntent的唯一方法是指定一个唯一的操作,这与我上面在Manifest中定义Receiver相冲突。还有其他的方法来区分我的警报的待定意图吗?我也尝试添加数据,但似乎没有触发清单中的接收器。

或者,如果我以编程方式为每个警报启动接收器,是否有办法在应用程序关闭时保持这些接收器?

谢谢。

在这里找到了解决方案:如何创建不同的pendingintent所以filterEquals()返回false?

使用PendingIntent的第二个参数。getBroadcast的工作是建立一个唯一的PendingIntent。没有必要有一个独特的行动,尽管这是我能找到的其他帖子建议的。

不知道现在该如何结束这个问题…

最新更新