gpt4 book ai didi

android - 如何在钛合金中向通知添加声音

转载 作者:行者123 更新时间:2023-12-03 01:53:47 25 4
gpt4 key购买 nike

我以这种方式创建通知:

var notification = Titanium.Android.createNotification({
contentTitle : 'teste #' + nId,
contentText : 'Click to return to the application.',
contentIntent : pending,
sound : Ti.Filesystem.getResRawDirectory() + 'am.mp3',
});

然后,我调用声音方法,但无法在Android手机上获得声音。我已经将'am.mp3'文件放在资源,资源-> android中,并创建了一个名为资源-> android->原始,资源-> android-> res->原始的文件夹,现在解决方案起作用了。我也尝试过:
sound : "/android/res/raw/am.mp3"

就像我对图像所做的一样

有人知道如何使它工作吗?

最佳答案

要创建原始资源,请将音频文件放在platform/android/res/raw文件夹中,并将其引用为:

notification.sound = Ti.Filesystem.getResRawDirectory() + audioFileName;

声音
要在第一次出现通知时播放声音,请为Notification对象的sound属性分配一个声音文件来播放。将文件放在 /platform/android/res/raw/文件夹中。通过使用 Ti.Filesystem.getResRawDirectory()方法来引用文件,以检索文件的位置,然后将文件名附加到末尾,例如 Ti.Filesystem.getResRawDirectory() + 'sound.wav'

默认情况下,每次应用程序调用 notify()方法时,都会播放声音。若要覆盖此行为,请将 Titanium.Android.FLAG_ONLY_ALERT_ONCE常量添加到Notification对象的flags属性。
var notification = Titanium.Android.createNotification({
contentTitle: 'Notification 2',
contentText : 'Just another notification',
contentIntent: Ti.Android.createPendingIntent({intent: Ti.Android.createIntent({})}),
icon: Ti.App.Android.R.drawable.warn,
number: 5,
when: new Date().getTime(),
// Sound file located at /platform/android/res/raw/sound.wav
sound: Ti.Filesystem.getResRawDirectory() + 'sound.wav',
});

来源 12

关于android - 如何在钛合金中向通知添加声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37351754/

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