通知不断响铃。怎么让它只响一次?

时间:2018-03-27 06:17:17

标签: android push-notification android-push-notification

我已将它与通知构建器一起使用

  final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NotificationChannelCreator.COMPLAIN)
            .setSmallIcon(R.drawable.prescient_logo)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent);


    showNotification(notificationBuilder);


}

private void showNotification(NotificationCompat.Builder notificationBuilder) {
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    android.app.Notification notification = notificationBuilder.build();
    notification.defaults |=  Notification.FLAG_ONLY_ALERT_ONCE;
    notification.flags = android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.FLAG_AUTO_CANCEL;   
    notificationManager.notify(12  , notification);
}

我仍在接受连续的声音 怎么解决呢?

0 个答案:

没有答案