java - Android 中自动取消通知

标签 java android android-notifications

我想通过setAutoCancle()方法关闭通知。 这是NotifactionExample的代码。

@SuppressWarnings("deprecation")
protected void notifactionAlert() {
    // TODO Auto-generated method stub

    NotificationManager myNotifaction = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    @SuppressWarnings("deprecation")
    Notification Notifaction = new Notification(R.drawable.notifaction,
            "Notifaction received.", System.currentTimeMillis());


    Intent notifactionIntent = new Intent(MainActivity.this, notify.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notifactionIntent, 0);
    Notifaction.setLatestEventInfo(MainActivity.this, "Notifaction.",
            "you get a new notifaction...", pendingIntent);
    myNotifaction.notify(9999, Notifaction);

}

我能做什么?

最佳答案

您所需要做的就是将 autoCancel 标志设置为 On。

Notifaction.flags |= Notification.FLAG_AUTO_CANCEL

关于java - Android 中自动取消通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32450875/

相关文章:

java - OpenCV 图像描述符到 JSON

兼容 Java 类名

android - 如何使用 super 用户编译 AOSP

android - 提醒功能

android - 如何仅在应用程序处于前台而不是从通知中捕获辅助功能事件?

android - 是否有一种直接的方法来响应用户单击通知来停止服务?

java - 为什么要运行?

java - 如何在不使用可比较和比较器接口(interface)的情况下对 map 进行排序?自定义排序怎么写?

java - 启动时 BottomNavigation 不会转到我的 fragment 图标

android - 我无法从 flickr 获取照片