I want to dismiss my notification when an action button is pressed, but the PendingIntents I'm using are unchangeable. Can I bundle pending intents together so that one intent can be fired and the other can dismiss my notification?

Details:

My notification has 3 action buttons tied to it (reply, like, share). Only 1 (like) of these action buttons has a PendingIntent that goes into my own app.

The other 2 PendingIntents (reply and share) are received by another app entirely (and I do not have access to their original Intent data as I copied the pending intent from that other app's notification)

I want to be able to dismiss my notification when the reply and share actions are pressed but their current PendintIntents open up their respective apps. How can I do both?

有帮助吗?

解决方案

Since PendingIntent implements Parcelable, you should be able to store your PendingIntents in the Intent that you send to your activity when the button is pressed.

For example:

Intent intent = new Intent(context, MyClass.class);
Bundle pendingIntentBundle = new Bundle();
pendingIntentBundle.putParcelable("pintent", pendingIntent);
intent.putExtra("pintent", pendingIntentBundle);
PendingIntent pendingIntent = PendingIntent.getBroadcast(spaContext, 0, intent, 0);

Then grab the bundle and pending intent and rebroadcast it when your MyClass gets it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top