gpt4 book ai didi

android - 如何在android中使用自定义声音设置通知

转载 作者:IT王子 更新时间:2023-10-28 23:49:37 25 4
gpt4 key购买 nike

我将 mp3 (kalimba.mp3) 文件复制到 res 文件夹中的 raw 文件夹中。但是当通知被触发时,它会产生默认的声音。

这是我发出通知的方式:

protected void GenerateNotify() {

NotificationManager myNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(android.R.drawable.ic_btn_speak_now,"hi",100);
Intent intent=new Intent(getApplicationContext(),as.class);
PendingIntent contentintent=PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0);
notification.setLatestEventInfo(getApplicationContext(), "Hi","date", contentintent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.sound = Uri.parse("android.resource://com.example.serviceproject/" + R.raw.kalimba);
myNotificationManager.notify(NOTIFICATION_ID,notification);
}

最佳答案

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;

if defined DEFAULT_SOUND, then the default sound overrides any sound

关于android - 如何在android中使用自定义声音设置通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13760168/

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