肿瘤康复网,内容丰富有趣,生活中的好帮手!
肿瘤康复网 > android notification点击无效 Notification.addAction在Android O中无效

android notification点击无效 Notification.addAction在Android O中无效

时间:2019-09-07 21:39:01

相关推荐

下面提到的代码适用于

android O verison下面的所有设备.对于android O,

addAction()方法不起作用,即按钮单击在

Android O中不起作用.

任何帮助,将不胜感激.

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Intent mediaPlayerReceiver = new Intent("com.consult.news.receiver.ACTION_PLAY");

mediaPlayerReceiver.putExtra("NewsArticle", news);

PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, mediaPlayerReceiver, PendingIntent.FLAG_UPDATE_CURRENT);

Intent dismissNotification = new Intent("com.consult.news.receiver.DISMISS");

dismissNotification.putExtra("Notification_ID", 1);

PendingIntent dismissNotificationIntent = PendingIntent.getBroadcast(context, 0, dismissNotification, PendingIntent.FLAG_UPDATE_CURRENT);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

String CHANNEL_ID = "my_channel_01";

String CHANNEL_NAME = "my Channel Name";

NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

notificationChannel.enableLights(true);

notificationChannel.setLightColor(Color.RED);

notificationChannel.setShowBadge(true);

notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

notificationManager.createNotificationChannel(notificationChannel);

}

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "my_channel_01")

.setSmallIcon(R.drawable.ic_notification_white)

.setColor(ContextCompat.getColor(context, R.color.accent))

.setContentTitle(context.getString(R.string.Consult_Univadis_Title))

.setStyle(new NotificationCompat.BigTextStyle().bigText(news))

.addAction(isPlaying ? R.drawable.ic_notification_white : R.drawable.ic_notification_white, isPlaying ? "Play" : "Pause", pendingIntent)

.addAction(R.drawable.ic_notification_white, "Close", dismissNotificationIntent)

.setOngoing(true)

.setAutoCancel(false);

notificationManager.notify(1, builder.build());

如果觉得《android notification点击无效 Notification.addAction在Android O中无效》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。