android - 单击 addAction 后 Android 通知不会关闭
问题描述
我已将 addAction 添加到我的 android 通知中,以让用户启动特定活动,它正在工作,但通知不会在单击时被清除,而当我单击通知而不是按钮时它会被清除
Intent openPostIntent = new Intent(getApplicationContext(), PostActivity.class);
openPostIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
openPostIntent.setAction(Intent.ACTION_MAIN);
openPostIntent.addCategory(Intent.CATEGORY_LAUNCHER);
openPostIntent.putExtra(POST_ID_KEY, post_id);
PendingIntent open_post_pi = PendingIntent.getActivity(getApplicationContext(),
1, openPostIntent, PendingIntent.FLAG_CANCEL_CURRENT);
通知
NotificationCompat.Builder status = new NotificationCompat.Builder(getApplicationContext(),CHANNEL_ID);
status.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_stat_name)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setContentTitle(notification_title)
.setContentText(message)
.setLargeIcon(profile_img)
.setDefaults(Notification.DEFAULT_LIGHTS )
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
.addAction(R.drawable.ic_post, "Open post", open_post_pi)
.setContentIntent(pendingIntent);
``
解决方案
推荐阅读
- android-studio - 缺少 Activity 和 Fragment+ViewModel 模板
- android - android FirebaseRecyclerAdapter 点击项目不起作用
- ibm-mq - 将单个消息发送到 IBM MQ 中的多个队列的最佳实践
- php - codeigniter中非对象的未定义变量和属性
- grails - 如何删除 grails 中的 spring 安全令牌?
- javascript - 为什么在 JavaScript 中没有提升条件时起作用?
- swagger - Swagger 如何对休息方法进行分组(API 文档)
- python - 在命名管道中获取分段错误(核心转储)错误
- javascript - 在html中创建可点击列表
- scala - 如何从具有特定项目的交叉构建的 sbt 多项目中删除 scala 版本