Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Firebase通知包含标题和消息_Android_Firebase_Notifications_Firebase Notifications - Fatal编程技术网

Android Firebase通知包含标题和消息

Android Firebase通知包含标题和消息,android,firebase,notifications,firebase-notifications,Android,Firebase,Notifications,Firebase Notifications,我正在使用教程使用Firebase发送推送通知 我如何在通知栏中同时显示标题和消息?在这里,我仍然在通知栏中以*Title*内容获取消息 正如您在截图中看到的,由于这个原因,我无法将完整的*消息和标题*一起交付给用户,因为在通知栏中标题最多有一行 我正在使用高级Rest客户端消息传递API传递如下通知: https://fcm.googleapis.com/fcm/send Content-Type:application/json Authorization:key=AIza*********

我正在使用教程使用Firebase发送推送通知

我如何在通知栏中同时显示标题和消息?在这里,我仍然在通知栏中以*Title*内容获取消息

正如您在截图中看到的,由于这个原因,我无法将完整的*消息和标题*一起交付给用户,因为在通知栏中标题最多有一行

我正在使用高级Rest客户端消息传递API传递如下通知:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIza************adrTY

{ "data": {
    "image": "https://ibin.co/2t1lLdpfS06F.png",
    "message": "Firebase Push Message Using API"
    "AnotherActivity": "True"
  },
  "to" : "f25gYF3***********************HLI"
}
代码

使用

setContentTitletitle可设置通知的标题和名称

setContentTexttext以设置文本

在您的情况下,您必须将代码更改为:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setLargeIcon(image)
                .setSmallIcon(R.drawable.firebase_icon)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(image))/*Notification with Image*/
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent)
                .setContentTitle(messageTitle) // here
                .setContentText(messageBody);  // and here
如果你想支持新的Android O通知,我建议你也花点时间学习NotificationChannel


这意味着我也必须使用这一行:String title=remoteMessage.getData.gettitle;就像在message中一样,我使用字符串message=remoteMessage.getData.getmessage;是的。remoteMessage.getData.getmessage转到NotificationCompat.Builder中的setContentText,remoteMessage.getData.gettitle转到setContentTitle
NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("My notification")
    .setContentText("Hello World!");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setLargeIcon(image)
                .setSmallIcon(R.drawable.firebase_icon)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(image))/*Notification with Image*/
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent)
                .setContentTitle(messageTitle) // here
                .setContentText(messageBody);  // and here