【问题标题】:Phonegap native notification soundsPhonegap 原生通知声音
【发布时间】:2017-06-15 10:49:00
【问题描述】:

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

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

仅供参考,我在我的应用中使用 Ionic。

谢谢。

【问题讨论】:

标签: cordova audio push-notification ionic


【解决方案1】:
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

【讨论】:

    【解决方案2】:

    你可以试试我的phonegap-push plugin,但这仅适用于安卓系统。您可以在此插件中控制振动、声音、灯光和铃声。设备准备好后使用PushNotification.showPushSettings(),它会弹出一个窗口。

    【讨论】:

    • 在 StackOverflow 上不鼓励仅链接的答案。请尝试在您的答案中添加尽可能多的内容。
    猜你喜欢
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多