单击addAction后不会取消Android通知

时间:2020-05-02 03:04:24

标签: android notifications

我已将addAction添加到我的android通知中,以允许用户启动特定活动,该通知正在运行,但是onclick不会清除通知,而当我单击通知而不是按钮时,通知会清除

 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);
``

0 个答案:

没有答案
相关问题