具有清单声明的唯一 PendingIntent

Unique PendingIntent with Manifest declaration

我正在创建一个 Android 应用程序,它以编程方式创建在应用程序关闭时持续存在的警报。为了让警报持续存在,我必须像这样在我的清单中定义接收器:

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

这是我目前创建 PendingIntents 的方式..

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 的唯一方法是指定一个唯一的操作,这与我在上面定义的清单中的 Receiver 冲突。还有其他方法可以为我的警报制作可区分的 PendingIntents 吗?我也尝试添加数据,但似乎没有触发清单中的接收器。

或者,如果我以编程方式为每个警报启动一个接收器,有没有办法让它们在应用程序关闭时保持不变?

谢谢。

在此处找到解决方案:How to create different pendingintent so filterEquals() return false?

使用 PendingIntent.getBroadcast 的第二个参数可以建立一个唯一的 PendingIntent。不需要一个独特的动作,尽管这是我能找到的所有其他 post 的建议。

现在不确定如何关闭问题...