三星Galaxy S6 android 7立即取消通知

时间:2017-09-01 18:42:20

标签: java android notifications samsung-galaxy

我使用此代码创建了通知:

Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

final int notificationID = NotificationID.getID();

PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationID, intent, PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notif_icon)
        .setContentTitle(messageTitle)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(messageTitle + "\n" +messageBody))
        .setContentText(messageTitle + " " +messageBody)
        .setAutoCancel(true)                
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationID, notificationBuilder.build());

这在许多设备上运行良好,但在三星Galaxy S6 android 7上,通知会立即取消。

我尝试使用正在进行的标记并且通知仍然可见,但这不是解决方案,因为用户无法通过滑动通知来取消它。

知道可能导致问题的原因吗?

1 个答案:

答案 0 :(得分:1)

从代码中删除setAutoCancel(true)。

<强> setAutoCancel()

  

Notification.Builder setAutoCancel(boolean autoCancel)make this   当用户触摸时,通知会自动解除。

参考:https://developer.android.com/reference/android/app/Notification.Builder.html#setAutoCancel(boolean)