Android-如何使用操作创建通知 [英] Android - How to create a Notification with Action
本文介绍了Android-如何使用操作创建通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建这样的通知.
I'm creating a notification like this.
Notification.Builder builder = new Notification.Builder(context);
builder.setContentTitle(notifyMessage1)
.setContentText(notifyMessage2)
.setSmallIcon(R.mipmap.ic_launcher);
Notification notification = builder.build();
我想通过以下方式将操作添加到通知中
I want to add a action to my notification with
builder.addAction();
要意识到addAction(icon, title, pendingIntent);
已弃用
我的目标是创建一个没有图标的通知动作,我该如何实现?
My geal is to create a notification action without an icon, how can i achieve that?
推荐答案
使用NotificationCompat代替Notification,如下所示:
Use the NotificationCompat instead of Notification like this:
Notification.Action action = new NotificationCompat.Action(icon, title, pendingIntent);
Notification notification = new NotificationCompat.Builder(context)
.addAction(action)
.build();
这篇关于Android-如何使用操作创建通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文