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. ftp_connect在PHP中返回NULL
- 3. getParameter在servlet中返回null
- 4. openStdDlg在Chrome中返回null
- 5. ExecuteScript在Appium中返回null?
- 6. Context.CurrentMiningModel在UDF中返回NULL
- 7. getActionBar()在FragmentActivity中返回null
- 8. 在HtmlAgilityPack中返回null
- 9. setAdapter()在ListFragment中返回null
- 10. getSupportActionBar()在Android中返回null
- 11. findViewById在AppCompatActivity中返回null
- 12. UserPrincipal.current在iis7中返回null,
- 13. getSVGDocument()在Safari中返回null
- 14. Tessseract在android中返回null
- 15. findviewbyid在Android中返回null
- 16. getActionProvider();在Android中返回null
- 17. readline()在Java中返回null
- 18. getActivity()在PreferenceFragment中返回null
- 19. System.IO.Path.GetExtension在ASP.NET中返回NULL
- 20. BitmapFactory.decodeByteArray在Android中返回null
- 21. mMenuDrawer在logcat中返回null
- 22. getInstitutions在AggCatSampleApp中返回null
- 23. cluster.getJob在hadoop中返回null
- 24. connection.getType()在ios中返回null
- 25. null == null返回false?
- 26. 返回NULL在C++
- 27. PropertyInfo.GetValue(null,null)返回null
- 28. jquery ajax在回应中返回null
- 29. DetailsView FindControl()在返回后返回null
- 30. JNI getmethodID只在ICS中返回NULL,但在Gingerbread中不返回
感谢弗兰克。我只是想出了一个解决方法,并发布我的答案,而不使用getMessageType()本身。 –