Default sound not playing in Android v9 but working on Andoird v7 - ionic v3 cordova push plugin

烈酒焚心 提交于 2020-01-04 02:02:10

问题


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));
  }

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));
  }

Node code: -

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
};

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.


回答1:


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

Hope this helps you.



来源:https://stackoverflow.com/questions/58319165/default-sound-not-playing-in-android-v9-but-working-on-andoird-v7-ionic-v3-cor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!