gpt4 book ai didi

android - 我可以在应用关闭时更改推送通知的声音吗?

转载 作者:行者123 更新时间:2023-12-03 02:10:36 26 4
gpt4 key购买 nike

当我通过GCM向Android手机发送通知时,我会发送一个声音名称,该声音名称会在应用运行或用户单击通知时播放。

我的问题是我可以更改通知的声音吗?不是在用户单击通知时而是在电话中弹出通知时。我知道有可能,当通知推送弹出时,Yo app会播放声音“YO”。

对不起,我的英语是:s,谢谢您的帮助!

最佳答案

构建通知时,可以使用setSound(uri)为通知设置声音。

public NotificationCompat.Builder setSound (Uri sound)

Set the sound to play. It will play on the default stream.

或者,您可以使用 setDefaults(Notification.DEFAULT_SOUND)播放默认声音。

例如 :
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setDefaults(Notification.DEFAULT_SOUND)
.setTicker (text)
.setSmallIcon(R.drawable.icon)
.setContentText (text)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(text))
.setAutoCancel(true).setNumber (4)
.setContentIntent(contentIntent);

mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

据我所知,在显示通知时会播放此声音(尽管我尚未检查)。但是,如果没有,则可以在调用 mNotificationManager.notify之前播放声音,而不管显示通知的代码中的通知如何(在您的广播接收器或Intent服务中)。

关于android - 我可以在应用关闭时更改推送通知的声音吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24507579/

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