Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了java – Android:管理多个通知大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在我的应用程序中创建多个通知.为了唯一地识别每个通知,我给了它们唯一的identifierId.以下是我的代码
private void updateNotification(int notificationId,int clockStatusID,CharSequence text) {
 //notificationmanager.cancel(notificationId);
// throws up an ongoing notification that the timer is running
Log.i("TIMERCOUNT","Notification id: " + notificationId);
Notification not = new Notification(clockStatusID,// the
    // icon
    // for
    // the
    // status
    // bar
    text,// the text to display in the ticker
    System.currentTimeMillis() // the timestamp for the
    // notification to appear
);
Intent intent = new Intent();
intent.putExtra("notificationID",notificationId);
intent.setAction("actionString" + System.currentTimeMillis());
intent.setClassName("com.chander.time.android.activities","com.chander.time.android.activities.Tabs");


not.setLatestEvenTinfo(self,getText(R.String.timer_notification_titlE),getText(R.String.timer_on_notification_text),PendingIntent
    .getActivity(this,intent,PendingIntent.FLAG_updatE_CURRENT));

not.flags += Notification.FLAG_ONGOING_EVENT;
not.flags += Notification.FLAG_NO_CLEAR;
notificationmanager.notify(notificationId,not);
}

问题:
当选择通知时,Tabs活动称为传递意图.我想访问在Tabs中选择的通知的唯一notificationId.我试图intent.putExtra()来保存notifyId的意图.但是,对于多个通知,它覆盖了notificationId并返回最新的通知.我不明白为什么会发生这种情况,我如何避免这种覆盖notificationId.@H_801_6@

谢谢,
钱德尔@H_801_6@

解决方法

我得到了答案.意图正在缓存.为了做一个新的意图,只需添加以下代码
saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis())));

这使得意图是独一无二的.@H_801_6@

另外,有人建议我使用以下代码来使意图独一无二:@H_801_6@

saveCallIntent.setAction("actionString" + System.currentTimeMillis());

它没有帮助我,但可能对别人有帮助.@H_801_6@

–Chander@H_801_6@

大佬总结

以上是大佬教程为你收集整理的java – Android:管理多个通知全部内容,希望文章能够帮你解决java – Android:管理多个通知所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。