2016-07-15 77 views
2
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{ 

    String TAG = "FirebaseMessagingService"; 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage){ 

     Log.i(TAG," input string :"+ String.valueOf(remoteMessage.getData())); 
     /** 
     * Parse remote input and pass id, action, frequency and payload to eventHandler. 
     * **/ 

     String messageType = remoteMessage.getMessageType();// messageType is null always 
     if(messageType.equalsIgnoreCase("Data")){ 
      Log.i(TAG, " Data notification received"); 
     } 
     else if(messageType.equalsIgnoreCase("Notification")){ 
      Log.i(TAG, " Push notification received"); 
     } 
} 

回答

0

谢谢。 我真的想出了一种方法来检查消息类型本身。以下内容适用于我,而不使用getMessageType。

Map data = remoteMessage.getData(); RemoteMessage.Notification notification = remoteMessage.getNotification();

if (data.isEmpty()) { // message type is notification. 
     parseDataMessage(remoteMessage); 
    } else { // message type is data. 
     parseNotificationMessage(remoteMessage); 
    } 
0

从它看起来像它的文档,你可以发送消息和使用SDK here时设置的参数。

public RemoteMessage.Builder setMessageType (String messageType)

然而,在发送使用火力地堡REST API消息时,我还没有看到指定消息类型的能力。

0

你应该尝试像这样...

if(getIntent().getExtras() != null && getIntent().getExtras().get("your_data_key") != null) { 
String strNotificaiton = getIntent().getExtras().get("your_data_key").toString(); }