默认声音无法在Android v9中播放,但可以在Andoird v7上运行-Ionic V3 Cordova Push Plugin [英] Default sound not playing in Android v9 but working on Andoird v7 - ionic v3 cordova push plugin

查看:46
本文介绍了默认声音无法在Android v9中播放,但可以在Andoird v7上运行-Ionic V3 Cordova Push Plugin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FCM在我的应用上发送通知. 以下是屏幕截图,我的工作方式.



如您所见,我启用了声音,并且该声音可以在Android v7上运行,但不能在其他装有Android v9的设备上运行



I am using FCM to send notification on my app. below are the screenshots, how I am doing.



As you can see I enabled the sound, and it is working on Android v7 but not on my other device with Android v9



这是我的离子应用程序上的代码...

Here is the code on my ionic app...

pushSetup() {
    this.push.hasPermission().then((res: any) => {
      if (res.isEnabled) {
        console.log("We have permission to send push notifications");
      } else {
        console.log("We do not have permission to send push notifications");
      }
    });

    // Create a channel (Android O and above). You'll need to provide the id, description and importance properties.


    const options: PushOptions = {
      android: {
        senderID: "############", //just hiding it :)
        sound: true,
        forceShow: true
      },
      ios: {
        alert: "true",
        badge: true,
        sound: "false"
      }
    };

    const pushObject: PushObject = this.push.init(options);

    pushObject
      .on("notification")
      .subscribe((notification: any) =>
        console.log("Received a notification", notification)
      );

    pushObject.on("registration").subscribe((data: any) => {
      console.log("device token -> " + data.registrationId);
      //TODO - send device token to server
    });

    pushObject
      .on("error")
      .subscribe(error => console.error("Error with Push plugin", error));
  }

我也尝试添加自定义声音,但仍然无法解决. 我正在使用@ ionic-native/push @ 4.20.0

I also tried to add the custom sound but still it didn't work out. I am using @ionic-native/push@4.20.0

也尝试通过创建渠道,这是离子代码.

tried by creating channel too, here is the ionic code.

 pushSetup() {
    this.push.hasPermission().then((res: any) => {
      if (res.isEnabled) {
        console.log("We have permission to send push notifications");
      } else {
        console.log("We do not have permission to send push notifications");
      }
    });

    this.push
      .createChannel({
        id: this.channelId,
        description: "Emergency Channel",
        importance: 4,
        sound: "sound1"
      })
      .then(() => console.log("Channel created"));

    // Create a channel (Android O and above). You'll need to provide the id, description and importance properties.

    const options: PushOptions = {
      android: {
        senderID: "xxxxxxxx", // just hiding
        sound: true,
        forceShow: true,
        vibrate: true
      },
      ios: {
        alert: "true",
        badge: true,
        sound: "true"
      }
    };

    const pushObject: PushObject = this.push.init(options);

    pushObject
      .on("notification")
      .subscribe((notification: any) =>
        console.log("Received a notification", notification)
      );

    pushObject.on("registration").subscribe((data: any) => {
      console.log("device token -> " + data.registrationId);
      //TODO - send device token to server
    });

    pushObject
      .on("error")
      .subscribe(error => console.error("Error with Push plugin", error));
  }

节点代码:-

var payload = {
  notification: {
    title: "Account Deposit",  //push notification title
    body: "A deposit to your savings account has just cleared.",  //push notification message
    soundname: 'sound1',
    android_channel_id: 'emergency'
  }
};

var options = {
  priority: "normal",
  timeToLive: 60 * 60
};

已经在config.xml中添加了此文件

Already added this file in config.xml

<resource-file src="src/assets/sounds/sound1.mp3" target="app/src/main/res/raw/sound1.mp3" />

文件也存在于以上代码中提到的两个文件夹中. 做完这些工作之后,电话现在会在收到通知但没有声音的情况下震动.

the files also exist in both the folders mentioned in the above code. after doing this much work, phone is now vibrating on notification but no sound.

推荐答案

我遇到了与您相同的问题,并将" ionic-native/push "更新为版本" 4.20.0" "

I had the same problem as you and updating the "ionic-native/push" to version "4.20.0"

npm install --save @ionic-native/push@4.20.0

希望这对您有所帮助.

这篇关于默认声音无法在Android v9中播放,但可以在Andoird v7上运行-Ionic V3 Cordova Push Plugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆