android - 如何以编程方式发送通知栏备份?

标签 android android-notifications

我进行了研究,我能找到的唯一答案是:

  1. 如何禁止下拉通知栏。
  2. 如何使用以下方式取消通知:

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

这两个都不是我所需要的,因为通知被取消了。我在通知中设置了两个操作:“关闭”和“打开 Activity ”。顾名思义,单击两者后,上面的代码将执行并清除通知,但不会导致通知栏返回。这是必需的,特别是当第二个通知操作导致 Activity 启动时。

我在 Android Lollipop 和 Nougat 上试过,通知栏都没有恢复。因此,如果有人可以告诉我这是否可能以及如何实现。 谢谢。

构建通知的代码:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder
            .setSmallIcon(icon).setTicker(message).setWhen(when)
            .setAutoCancel(true).setContentTitle("Kindly record your Voice")
            .setColor(Color.RED);


    notificationIntent = new Intent(this,ReminderReceiver.class);
    notificationIntent.setAction("Record");
    PendingIntent pendIntent1 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(R.drawable.common_google_signin_btn_icon_dark, "Record", pendIntent1);


    notificationIntent2 = new Intent(this, ReminderReceiver.class);
    notificationIntent2.setAction("Dismissed");

    PendingIntent pendIntent2 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(R.drawable.starticon, "Dismiss", pendIntent2);

    notificationIntent3 = new Intent(this, CancelReceiver.class);
    PendingIntent pendIntent3 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent3, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(pendIntent3);

    notification = builder.build();


    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(1, notification);

最佳答案

可能看起来很奇怪,但是当存在其他通知时通知栏不会上升。如果您的通知是唯一的通知,则该栏会在点击后自动向上滑动。

关于android - 如何以编程方式发送通知栏备份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45479527/

相关文章:

android - 通知在 Ginger Bread 中不显示,但在 JellyBean 中有效

android - 如何在点击 nokia-x 时清除通知托盘中的通知

android - 待定 Intent 未按预期工作

android - 在android中点击通知进入我的应用

java - 更新 SQLite Android 列的所有行

java - addView 添加 View 但没有显示它

java - 如何使所有语言的 View 顺序相同

android - 如何从 firebase 数据库中检索包含子名称的字符串列表?

android - 屏幕关闭时带有 setFullScreenIntent 的通知不显示 Activity

java - 在 android 中创建文件并写入该文件时遇到问题。未处理的异常 java.io.FileNotFoundException