I have an Android library that has a Service that creates a Notification. From what I understand Notification must have a contentIntent (PendingIntent) set or a runtime exception will be thrown.
The problem is that I want users to be able to use this Service as is, or extend it, so that they can set the PendingIntent themselves through a callback during the creation of the Notification. However, if they choose not to do this, I need to set the PendingIntent to something so that there is no exception. Is there any way to create a dummy PendingIntent that just acts as a fill-in?
Here's an example of the code from the createNotification method:
PendingIntent p;
if(getPendingIntentCallback != null) {
p = getPendingIntentCallback.getPendingIntent();
}
else {
p = ?;
}
notification.contentIntent = p;
PendingIntent pi=PendingIntent.getBroadcast(this, 0, new Intent("DoNothing"), 0);
This worked for me. It will launch a broacast for a "DoNothing" action. I hope nobody will listen for a "DoNothing" broadcast and do something as a reaction to it. But if you prefer you can construct something more exotic. Note: I'm using this just as a temporary placeholder. I will substitute it with something more useful for the user as I will advance in my application development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With