Я использую FCM для отправки уведомлений в свое приложение. ниже скриншоты, как я делаю.
Как вы видите, я включил звук, и он работаетна Android v7, но не на моем другом устройстве с Android v9
Вот код моего ионного приложения...
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
, также пытаясь создать канал, вот ионный код.
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" />
, файлы также существуют в обеих папках, указанных в приведенном выше коде. после выполнения этой большой работы телефон теперь вибрирует при уведомлении, но без звука.