gpt4 book ai didi

java - Android 通知多个默认值

转载 作者:行者123 更新时间:2023-11-29 19:25:18 25 4
gpt4 key购买 nike

下面是我用来向用户发送通知的代码:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Secure Mail")
.setContentText("New Secure Mail Received")
.setAutoCancel(true)
.setOnlyAlertOnce(true);
/*
.addAction(R.drawable.ic_reply_white_24dp, "Reply", contentIntent)
.addAction(R.drawable.ic_reply_all_white_24dp, "Reply All", contentIntent)
.addAction(R.drawable.ic_forward_white_24dp, "Forward", contentIntent);
*/

builder.setContentIntent(contentIntent);
builder.setAutoCancel(true);
builder.setOnlyAlertOnce(true);

if (ringtone.equals("")) {
Log.d(TAG, "Default Sound");
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(soundUri);
} else if (!ringtone.equals("Silent")) {
Log.d(TAG, "Selected sound: " + Uri.parse(ringtone));
//Uri currentRintoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE);
Uri currentRintoneUri = Uri.parse(ringtone);
builder.setSound(currentRintoneUri);
}
//builder.setLights(Color.BLUE, 500, 500);

if (vibrate.equals("true")) {
Log.d(TAG, "Vibrate is enabled");
//long[] pattern = {500, 500, 500, 500, 500, 500, 500, 500, 500};
//builder.setVibrate(pattern);

builder.setDefaults(Notification.DEFAULT_VIBRATE);
}

builder.setStyle(new NotificationCompat.InboxStyle());

/*
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
*/

builder.setDefaults(Notification.FLAG_AUTO_CANCEL);
builder.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE);

NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
manager.notify(1, builder.build());

我需要能够有多个默认设置(振动、自动取消和提醒一次),但似乎只有最后一个(提醒一次)会起作用,而其他的则不会。

我尝试使用 Notification 对象,然后设置标志(这似乎适用于我的设备上的振动、自动取消和提醒,但后来其他用户报告说通知现在根本无法通过)。

因此,如何使用我当前的代码同时设置振动、自动取消和提醒一次这三个默认值?

最佳答案

您可以使用 | 运算符来组合默认值。

builder.setDefaults(Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE);

关于java - Android 通知多个默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41521265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com