how to send customized message to android device using php library

0 votes
i used app42 php sdk to sending push notifications. if i send normal string as message then it works fine and i receive that notification but when i send customized push notification to sending extra data than it not works it sends it as a string, i tried it using json and array format, but still it not works,

please help me
asked Jul 16, 2014 in App42 Cloud API-BaaS by sergio (10 points)
Can you add more context regarding your query like what type of exception you are getting while sending a message? As well, can share the code snippet, it will help us to understand and solve your query better.
Well what I mean to say is that when I sent plain string to android device, we are good. But when I tried to send multiple key values (i tried json and PHP array), we just got the the array/json as it is. e.g. consider a message

{
  "title": "testing",
  "message": "testing",
  "id": 123
  
}

When I tried to send it, I got an alert with complete message (on notification window without parsing) but when I tried to send the same message using Google Cloud Messaging (GCM) we get the parsed message and on notification window we only get title and message.

Hope I make myself clearer.

Please advice what I am missing...

1 Answer

0 votes
Hi Sergio,
 
Thanks for sharing the details with us.

When you send the json message from php web portal to Android device, convert that json string into Json Object in Receiver class of Android application as explained in below code snippet:


String message = intent.getExtras().getString("message");

JSONObject jsonMessage=new JSONObject(message );
String myPushMessage=jsonMessage.optString("message", "default message ");
String title=jsonMessage.optString("title", "Default title");
int id=jsonMessage.optInt("id", 0);
After getting the information in json object and set the information in title var by using above code snippet, you can set your title and message in notification as explained in below code:
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(myPushMessage)
.setContentIntent(intent)
.setSmallIcon(icon)
.setWhen(when)
.setLights(Color.YELLOW, 1, 2)
.setAutoCancel(true)
.build();
Let me know if it answer your question.
 
Thanks

 

answered Jul 18, 2014 by hs00105 (517 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...