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");
}
}
2
A
回答
1
我不确定getMessageType()
应该返回什么。但它似乎不太可能返回Data
或Notification
,因为a single message can contain both notification and data information。
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(); }
相关问题
- 1. Target Unreachable,'null'在JSF中返回null
- 2. getSVGDocument()在Safari中返回null
- 3. ftp_connect在PHP中返回NULL
- 4. getActivity()在PreferenceFragment中返回null
- 5. getActionBar()在FragmentActivity中返回null
- 6. mMenuDrawer在logcat中返回null
- 7. connection.getType()在ios中返回null
- 8. UserPrincipal.current在iis7中返回null,
- 9. findViewById在AppCompatActivity中返回null
- 10. getActionProvider();在Android中返回null
- 11. readline()在Java中返回null
- 12. cluster.getJob在hadoop中返回null
- 13. BitmapFactory.decodeByteArray在Android中返回null
- 14. Context.CurrentMiningModel在UDF中返回NULL
- 15. ExecuteScript在Appium中返回null?
- 16. null == null返回false?
- 17. PropertyInfo.GetValue(null,null)返回null
- 18. DetailsView FindControl()在返回后返回null
- 19. JNI getmethodID只在ICS中返回NULL,但在Gingerbread中不返回
- 20. UISwitch返回NULL?
- 21. getElementById返回null
- 22. ListView.getTag()返回null
- 23. LocationManager返回null
- 24. BitmapFactory.decodeFile()返回null
- 25. FindFragmentByTag返回null。
- 26. GetEditMenu()返回NULL
- 27. mysql_fetch_assoc返回NULL
- 28. cvCapturefromCAM()返回NULL
- 29. Android:TelephonyManager.getSimSerialNumber()返回null
- 30. WindowsFromDc返回null
感谢弗兰克。我只是想出了一个解决方法,并发布我的答案,而不使用getMessageType()本身。 –