Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

firebase - How to get value from FCM data message in Android?

I'm trying to implement FCM notification in my app. I have read FCM data message type will receive notification even when app is in background so am trying to implementing that in onMessageRecieved method am getting unexpected response like this:

{title =2, message={"Status":"UNASSIGNED","CompanyName":"gd","LastModifiedDateTime":"2017-04-25 18:59:41","IsPartRequired":false,"ProblemCategory":"CONFIGURATION","IsGeneralClaim":false,"RegistrationID":1057,"IncidentCode":"INS/2017/04/25-0010","StatusID":0,"CreatedDateTime":"2017-04-25 18:59:41","IsInstallationCall":false}}

Don't know how to parse this get separate value from title and message let me post my firebase message code:

public class FireBaseMessage extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMsgService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
      Map<String,String> data = remoteMessage.getData();
        Log.d(TAG, "From: " + data.toString());
// 
}
}

In this log message am getting response like that how to get value from that is try like:

int title=data.get("title"); 

getting null pointer as this is not in valid format. In my server side i have am trying to post json format like this:

{
   "to":"es_OToDkj00:APA91bFqxbVMAaXy5fPtDbNVAkIwyVrPCmfGci2otHZPvdRoXPv-oDdjgtLR92Nqe8w6f57nCVceLbc3_zBWsInG9g1Pfdp3LvsMKyuaiYps0L1y3tn0N0XbzGseEI6jyiqs1r-sT9lb",
   "data":{
      "message":{
         "RegistrationID":1057,
         "IncidentCode":"INS/2017/04/25-0010",
         "CompanyName":"ABM INFOTECH",
         "StatusID":5,
         "Status":"ASSIGNED",
         "CreatedDateTime":"2017-04-25T12:03:45",
         "LastModifiedDateTime":"2017-04-25T18:59:41",
         "ProblemCategory":"CONFIGURATION",
         "IsPartRequired":false,
         "IsInstallationCall":false,
         "IsGeneralClaim":false
      },
      "title ":"1"
   }

Don't know where I'm making a mistake. Can anyone help me? Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...