【发布时间】:2018-04-26 19:01:05
【问题描述】:
我认为在 android 中显示动作的常用方式有点难以点击和被发现。用户需要执行两个操作(滑动通知,然后单击操作)。
所以我想在通知的右侧添加一个按钮,这样点击起来会更方便。
我发现的唯一方法是使用MediaStyle,但它有一些问题:
- 它会创建一个通知,但它全是黑色的
- 我不希望它像这样展开
- 我想添加常用操作(齿轮图标,配置屏幕的快捷方式)
到目前为止我得到的代码:
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle("WorkTime")
.setContentText("Estimativa de saída: 19:00h")
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setOngoing(true)
.addAction(R.drawable.ic_fingerprint_black_24dp, "bater ponto", null)
.setStyle(
new android.support.v4.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0)
)
.build();
notificationManager.notify(1, notification);
我需要implement a custom layout 来接收通知吗?
PS:您可能会注意到,smallIcon 不起作用。一些提示将不胜感激,但我知道那将是另一个问题,我想我可以自己找到解决方案。
【问题讨论】:
标签: java android push-notification notifications kotlin