我想为音乐播放器应用创建通知。我想在上一个动作,播放/暂停,下一个动作的通知上添加三个“动作”按钮。对于操作,我想从drawable(R.drawable.ic_pervious,R.drawable.ic_pause和R.drawable.ic_next)添加图标。经过研究,我使用了以下代码,但图标对我不可见。
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(getString(R.string.app_name))
.setContentText("Apna time ayega")
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.setContentIntent(resultPendingIntent) //intent
.addAction(R.drawable.ic_pervious, "", pendingPrevIntent)
.addAction(R.drawable.ic_pause, "", pendingPlayIntent)
.addAction(R.drawable.ic_next, "", pendingNextIntent)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1, notificationBuilder.build());
startForeground(1, notification);
答案 0 :(得分:0)
从android牛轧糖开始,通知中没有通知操作图标。但是,通知操作图标是必需的,并且它们显示在较早的android和Android wear中。
来源-https://android-developers.googleblog.com/2016/06/notifications-in-android-n.html
答案 1 :(得分:0)
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
notificationBuilder.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(getString(R.string.app_name))
.setContentText("Apna time ayega")
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.setContentIntent(resultPendingIntent) //intent
.addAction(R.drawable.ic_pervious, "", pendingPrevIntent)
.addAction(R.drawable.ic_pause, "", pendingPlayIntent)
.addAction(R.drawable.ic_next, "", pendingNextIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1, notificationBuilder.build());
也许这会对您有所帮助