2016-11-02 12 views
0

Firebase Cloud Messagingを使用しようとしています。 Node.jsサーバーから通知システムに登録されているアプリケーションに通知を送信します。FCM通知のタイトルは「FCMメッセージ」のままです

私の問題は、Android 5.1では、nofitification jsonでtitle属性を設定しても、通知が「FCMメッセージ」です。 Android 6.0では正常に動作します。デバイスを再起動しようとしました。

enter image description here

そして、これは私が通知を送信するために使用するコードです:あなたは、私が送った通知のタイトルは「マイアプリケーション名」であるが、デバイス上で、それは「FCMを示して見ることができるように

function sendNotificationToUser(userToken, message, onSuccess) { 
    request({ 
    url: 'https://fcm.googleapis.com/fcm/send', 
    method: 'POST', 
    headers: { 
     'Content-Type' :' application/json', 
     'Authorization': 'key='+API_KEY 
    }, 
    body: JSON.stringify({ 
     notification: { 
     "title": 'My App Name', 
     "body": message, 
     "sound": 'default' 
     }, 
     to : userToken 
    }) 
    }, function(error, response, body) { 
    if (error) { console.error(error); } 
    else if (response.statusCode >= 400) { 
     console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage); 
    } 
    else { 
     onSuccess(); 
    } 
    }); 
} 

メッセージ"。

私は何をしなければなりませんか?

+0

ですか? –

+0

これはサーバー側ではない問題、問題はAndroidコードonMessageReceivedです –

答えて

2

onMessageReceivedコールバックに関連する問題であることが判明しました。

enter image description here

あなたはあなたがタイトルを渡した後、remoteMessage.getNotification().getTitle()でそれを受信する必要がreceive a FCM guide

2

上で見ることができるように、これはタイトルをキャッチして、トップに表示したり、ウェブから完全なJSONを通過し、

:ここでは、この

JSONObject jsonObject = new JSONObject(remoteMessage.getData());

のように受信が完了する方法でありますそれはonMessageReceived` `によって、または通知トレイに扱われたことを通知

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    // ... 
    // TODO(developer): Handle FCM messages here. 
    // Not getting messages here? See why this may be: https://firebase.google.com/support/faq/#fcm-android-background 
    Log.d(TAG, "From: " + remoteMessage.getFrom()); 

    // Check if message contains a data payload. 
    if (remoteMessage.getData().size() > 0) { 
     Log.d(TAG, "Message data payload: " + remoteMessage.getData()); 
    } 

    // Check if message contains a notification payload. 
    if (remoteMessage.getNotification() != null) { 
     Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); 
    } 

    // Also if you intend on generating your own notifications as a result of a received FCM 
    // message, here is where that should be initiated. See sendNotification method below. 
} 

Ref link