默认声音在 Android v9 中不播放,但在 Android v7 上运行 - ionic v3 cordova 推送插件

2023-12-29

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

enter image description here

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

enter image description here

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

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/[电子邮件受保护] /cdn-cgi/l/email-protection

也尝试创建通道,这是离子代码。

 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 中添加此文件

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

这些文件也存在于上面代码中提到的两个文件夹中。 做了这么多工作后,手机现在在收到通知时振动,但没有声音。


我遇到了和你一样的问题并更新了“离子本机/推“到版本”4.20.0"

npm install --save @ionic-native/[email protected] /cdn-cgi/l/email-protection

希望这对您有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

默认声音在 Android v9 中不播放,但在 Android v7 上运行 - ionic v3 cordova 推送插件 的相关文章

随机推荐