gpt4 book ai didi

cordova - Phonegap 原生通知声音

转载 作者:行者123 更新时间:2023-12-02 23:48:09 25 4
gpt4 key购买 nike

有什么方法可以在 Phonegap 中使用 native /默认通知声音进行通知(特别是用于 phonegap 的 PushPlugin)?目前它确实使用我的默认通知声音,但是,我想添加自定义通知声音的选项以使用手机上已有的任何默认声音。

这可能吗?如果是这样,我怎样才能在 iOS 和 Android 上实现它?

仅供引用,我正在为我的应用程序使用 Ionic。

谢谢。

最佳答案

import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import java.io.IOException;

String soundName = extras.getString("sound");
if (soundName != null) {
MediaPlayer player = new MediaPlayer();
AssetFileDescriptor file;
try {
file = getAssets().openFd("www/sounds/"+soundName+".mp3");
player.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
mBuilder.setDefaults(defaults);
player.prepare();
player.start();
} catch (IOException e) {
}
}

mNotificationManager.notify((String) appName, notId, mBuilder.build());

来自 here

关于cordova - Phonegap 原生通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28639260/

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