Android 如何在后台编辑来自Firebase的通知?

Android 如何在后台编辑来自Firebase的通知?,android,android-studio,firebase,firebase-cloud-messaging,Android,Android Studio,Firebase,Firebase Cloud Messaging,我有一个从Firebase获取通知的应用程序,但它没有声音和应用程序图标 在onMessageReceived()方法中,我可以编辑通知,但它在后台不起作用 解决方案是什么?从服务器发送: { "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification" : { "body" : "Hello World!", "title" : "My app", "icon

我有一个从Firebase获取通知的应用程序,但它没有声音和应用程序图标

在onMessageReceived()方法中,我可以编辑通知,但它在后台不起作用

解决方案是什么?

从服务器发送:

  {
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "Hello World!",
      "title" : "My app",
      "icon" : "myicon"
      "sound":"mysound"
    }

  }
声音文件必须在/res/raw/中,图标必须在/res/drawable中

从Firebase控制台

无法在应用程序被终止时编辑通知,因为android系统会处理通知。

请检查此代码

 private void showNotification(NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound)
{
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.addLine(message);
    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(inboxStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Config.NOTIFICATION_ID, notification);
}

是否将代码“code”@添加到MessageReceived(RemoteMessage RemoteMessage){Intent msgrcv=new Intent(this,MyServer.class);msgrcv.putExtra(“message”,RemoteMessage.getNotification().getBody());sendBroadcast(msgrcv);}请提供完整示例您只需从服务器发送json(带有参数sound和icon),或从firebase发送json(带有参数),系统通知中的android将播放声音并显示您的图标,您的保存在/res/raw/和/res/drawable中。您看到了whatsapp吗??我想做我的通知这个我在哪里可以使用这个你可以在你的on-onMessageReceived()方法中使用这个代码。但是没有在backgroundfirebase中调用的onMessageReceived()方法将通知发送到onMessageReceived(),然后我们可以使用给定的代码编辑通知。如果你想在Firebase本身中进行更改,那么据我所知,在那里是不可能编辑的。您只能在onMessageReceived()中编辑通知。