gpt4 book ai didi

安卓通知生成器 : How to setSound so that sound plays in a looper

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:37:23 26 4
gpt4 key购买 nike

我正在执行如下通知。默认警报声音播放正常,但只有一次。我想要的只是重复播放直到注册水龙头。

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("I Am Fine")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(NOTIFICATION_MESSAGE))
.setContentText(NOTIFICATION_MESSAGE)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mBuilder.setSound(alarmSound,AudioManager.STREAM_MUSIC);

setSound 的第二个参数没有显示任何效果。请帮忙!

最佳答案

您必须为通知使用 FLAG_INSISTENT。来自documentation :-

public static final int FLAG_INSISTENT

Bit to be bitwise-ored into the flags field that if set, the audio will be repeated until the notification is cancelled or the notification window is opened.

Constant Value: 4 (0x00000004)

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Uri soundUri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext()).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title").setContentText("message")
.setSound(soundUri); // This sets the sound to play

Notification mNotification = mBuilder.build();

mNotification.flags |= Notification.FLAG_INSISTENT;

// Display notification
notificationManager.notify(1, mNotification);

关于安卓通知生成器 : How to setSound so that sound plays in a looper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26631651/

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