我有一个Android库,其中包含一个创建通知的“Service”。据我所知,“Notification”必须设置“contentIntent”(“PendingIntent”),否则会抛出运行时异常。
问题在于,我希望用户能够直接使用这个“Service”,或者通过回调扩展它们自己来设置“PendingIntent”以便在创建“Notification”时使用。但是,如果他们选择不这样做,我需要设置“PendingIntent”为某些内容,以避免发生异常。是否有办法创建一个虚拟的“PendingIntent”作为填充?
以下是“createNotification”方法的代码示例:
问题在于,我希望用户能够直接使用这个“Service”,或者通过回调扩展它们自己来设置“PendingIntent”以便在创建“Notification”时使用。但是,如果他们选择不这样做,我需要设置“PendingIntent”为某些内容,以避免发生异常。是否有办法创建一个虚拟的“PendingIntent”作为填充?
以下是“createNotification”方法的代码示例:
PendingIntent p;
if(getPendingIntentCallback != null) {
p = getPendingIntentCallback.getPendingIntent();
}
else {
p = ?;
}
notification.contentIntent = p;