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
这是我的离子应用程序上的代码......
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" />
这些文件也存在于上面代码中提到的两个文件夹中。
做了这么多工作后,手机现在在收到通知时振动,但没有声音。