我正在从firebase向我的Android应用程序发送推送通知.但是当我的应用程序处于后台时,不会调用firebase onMessageReceived方法而是调用firebase向系统发送通知,以便在系统托盘中显示通知.通知出现在系统托盘中但没有通知声音,即使我已在系统设置中允许我的应用程序发出通知声音.
当从firebase收到通知时,我可以做什么来播放通知声音.
这就是我从firebase向我的应用Blogpost链接发送通知的方式.
notifications android push-notification firebase firebase-cloud-messaging
我使用来自云功能的 FCM 推送通知。这适用于 iOS 和 Android,并显示适当的图标并在 iOS 上播放自定义声音。
除了 Android 的自定义声音外,一切正常,它只是播放默认声音。
我创建了一个文件夹并将我的声音文件添加到其中,如下所示: android\app\src\main\res\raw\mp3_example.mp3
这个mp3有27秒长。我也试过 .wav 和 .aiff。
我读到我可能必须为更高版本的 Android 创建一个推送通知渠道,因此它可能与此有关。我尝试创建一个频道并使用来自云功能的 channelID 并且它可以工作但没有声音只是振动。
测试设备是运行 Android 8 的 Moto G6。我正在使用:FCM Firebase Cloud Functions Ionic 4 Capacitor https://github.com/stewwan/capacitor-fcm
云功能:
const notification: admin.messaging.Notification = {
title: title,
body: body
}
const message: admin.messaging.Message = {
notification,
topic: 'QMTBC',
android:{
notification:{
sound: 'mp3_example.mp3',
icon: 'push_logo',
color: '#000000'
}
},
apns:{
payload:{
aps: {
sound: 'gears-short.wav'
}
}
}
}
return admin.messaging().send(message)
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import { FCM …Run Code Online (Sandbox Code Playgroud)