昨天谷歌在Google I/O上展示了基于新Firebase的新通知系统.我在Github上尝试了这个新的FCM(Firebase云消息传递)示例.
尽管我已声明了特定的drawable,但通知的图标始终是ic_launcher
为什么?以下是处理邮件的官方代码
public class AppFirebaseMessagingService extends FirebaseMessagingService {
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should …Run Code Online (Sandbox Code Playgroud) android push-notification googleio firebase firebase-cloud-messaging
我在Android应用中使用Firebase推送通知.我可以使用自定义图标正确发送通知,但我还没有设法播放我的自定义声音.我总是得到设备的默认声音.
{
"registration_ids": "myToken",
"notification": {
"body": "my body",
"title": "my title",
"icon": "ic_notification",
"sound": "mysound.mp3" // I tried "mysound", "mysound.wav"...
},
"priority": "high"
}
Run Code Online (Sandbox Code Playgroud)
自定义声音位于/ res/raw中
我能够使用onMessageReceived和Firebase数据消息播放自定义声音,但不能使用Firebase通知消息.
我的Android设备是小米米A1和奥利奥8.1.也尝试了与小米米A2相同的结果.
我尝试使用php和curl,使用node.js ...总是一样的问题,我得到我的默认声音.
UPDATE
使用此node.js代码也不起作用:
var registrationToken = 'xxxxxx';
var message = {
notification: {
title: 'my title',
body: 'my body',
},
android: {
ttl: 3600 * 1000,
notification: {
color: '#ff0000',
sound: 'mysound.mp3'
}
},
token: registrationToken
};
Run Code Online (Sandbox Code Playgroud) 我正在从 Firebase 向我的 Android 应用程序发送推送通知,但它仅在收到通知时播放默认声音。
\n\n我已在 fcm 通知对象中设置了自定义声音参数{\xe2\x80\x9csound\xe2\x80\x9d:\xe2\x80\x9dnotificationsound.mp3\xe2\x80\x9d},并且该文件根据(https://firebase.google.com/docs/cloud-messaging/http-server-ref)存在于 res/raw 文件夹中\n但是它\xe2\x80\x99s 仍在所有应用程序状态(后台、前台和终止)上播放默认声音。\n这是我在 Android 上发送通知的请求正文:
{\n"to" : \xe2\x80\x9csome id\xe2\x80\x9d,\n"notification": {\n"title":"asdasd",\n"body":"sdsad",\n"click_action" : "MAIN",\n"sound":"notificationsound.mp3"\n},\n"data": {\n"title" : "Something",\n"body" : "Important",\n"type" : "message"\n},\n"priority": "high"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我可以做什么来播放自定义通知声音。
\n