小编use*_*947的帖子

单击时删除Android删除通知(由mNotifyBuilder创建)

我发现很多答案,但没有帮助:(我有这个代码:

private static void generateNotification(Context context, String message) {
    int icon = R.drawable.icon;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    int notifyID = 96;
    NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(context)
        .setContentTitle("MyApp")
        .setContentText(message)
        .setDefaults(Notification.DEFAULT_ALL)
        .setAutoCancel(true)
        .setSmallIcon(icon);

    Notification notification = mNotifyBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify(notifyID, notification);
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我点击通知没有任何事情发生,它仍然存在.在文档中,我需要使用:

.setAutoCancel(true)
Run Code Online (Sandbox Code Playgroud)

有人有类似的问题,有人告诉他使用:

notification.flags |= Notification.FLAG_AUTO_CANCEL;
Run Code Online (Sandbox Code Playgroud)

我使用两者,但没有结果:(非常感谢你的答案.:)

notifications android

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

notifications ×1