2016-11-02 5 views
0

Firebase Cloud Messaging을 사용하려고합니다. 알림 시스템에 등록 된 내 앱으로 Node.js 서버의 알림을 보냅니다.FCM 알림 제목이 "FCM 메시지"로 유지됩니다.

제 문제는 안드로이드 5.1에서 nofitification json에서 title 속성을 설정하더라도 알림이 "FCM Message"입니다. 그것은 안드로이드 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` '또는 알림 트레이에 처리 된 통지 6,

@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