2017-08-10 10 views
0

両方は私が見ることができますどのようにFirebaseFirebase通知は、タイトルとメッセージ

を使用してpush notificationを送信するためにthisチュートリアルを使用しています含まれていTitle and Message両方の通知バーenter code here(それでも私は、通知バーでmessage*Title*などのコンテンツを取得していますで)...

あなたはthisscreenshotで見ることができるように(このため、私はをunableからdeliverが完了しています私はこのような通知を送達するためにAdvanced Rest Client (Messaging API)を使用していますユーザーへ、通知バーのタイトルに制限maximum 1 lineを持っているので)

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" 
} 

コード

/** 
    * Create and show a simple notification containing the received FCM message. 
    */ 

    private void sendNotification(String messageBody, Bitmap image, String TrueOrFalse) { 
     Intent intent = new Intent(this, MainActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     intent.putExtra("AnotherActivity", TrueOrFalse); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
       PendingIntent.FLAG_ONE_SHOT); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setLargeIcon(image)/*Notification icon image*/ 
       .setSmallIcon(R.drawable.firebase_icon) 
       .setContentTitle(messageBody) 
       .setStyle(new NotificationCompat.BigPictureStyle() 
         .bigPicture(image))/*Notification with Image*/ 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); 
    } 

答えて

1

使用

setContentTitle("title")タイトルと通知を設定する

setContentText("text")テキストを設定します。あなたのケースでは

A example from Android Developers:

NotificationCompat.Builder mBuilder = 
    new NotificationCompat.Builder(this) 
    .setSmallIcon(R.drawable.notification_icon) 
    .setContentTitle("My notification") 
    .setContentText("Hello World!"); 

あなたはにあなたのコードを変更する必要があります:あなたは新しいをサポートするためにしたい場合、私は、あなたにもNotificationChannelを勉強し、いくつかの時間がかかることをお勧めします

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 example

+0

これは私もこの行を使用する必要があることを意味します:String title = remoteMessage.getData()。get( "title");メッセージの場合と同じように、私はString message = remoteMessage.getData()。get( "message");を使用しています。 – Sophie

+1

Yeap。あなたの 'NotificationCompat.Builder'の' setContentTitle'に 'remoteContent.getData()。get(" message ")'が 'setContentText'と' remoteMessage.getData()。get( "title") 'に行きます。 – GuilhermeFGL