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

Viewed 843

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

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 Answers

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.

Related