Unity Push Notification Android Extra Data

0 votes
Hello,

i'm working in a game and i need to send extra data to the game throw push notification, is there  a way to do this in Android? using Unity.

Thanks in advance.
asked May 8, 2015 in App42PaaS & BPaaS by jaime.franco (10 points)

1 Answer

0 votes

Hey Jaime, Yes, You can easily send extra data to game using Push Notification. You can find a complete tutorial of Push Notification integration on Unity Android game.

Let me know if it helps.

Thanks

Vishnu Garg

 

answered May 9, 2015 by Vishnu Garg (674 points)
Hi Vishnu,
As per the documentation here http://api.shephertz.com/app42-docs/push-notification-service/?sdk=android#send-custom-push-message-to-user-in-key-value-or-json-format
there is no way to do send key value pairs in Unity? How do I send extra data with the push notification that has data related to the game and does not need to be displayed to the user in the push notification?
Hey, If you won't want to display it to user than, You can send the data with Dashboard, but you need to modify the existing Android library plugin accordingly.
Currently it shows all the message that is receiving from AppHQ side.You can also send extra data in key value pairs as well.
I need to send the data from within the game itself. For this, I need to modify the existing android jar file? I thought since the method exists for other platforms, it would exist for unity too.
In AppHQ dashboard we have recently provide a feature in which you can send extra Data with key value pair with the message, currently working unity sample is not updated to that scenario, we are planning to update this soon.

You can do one more this can send message in JSON format and based on that can modify the Android library as well.
Any steps to update the anroid library? Also, by when will the unity sample and PushSample plugin be updated to include these features?
It will update soon with all the new features like Rich/Geo and Extra Data Push.
But If you can share the Json you want to send with the message I can built the same library for you.
For the json, u need the exact value of the key and the value of the data that is to be sent? or can it be generic?
At various stages in the game, different data needs to be sent.
It can be generic but must contain a key message that should be shown on Notification.Please find the dropBox link of that library
https://www.dropbox.com/s/tjrbryn8lf0b96a/app42pushservice.jar?dl=0
If you sending data in Json from your game json must contains "message" key that should be shown on the Notification.
All the Json data you will be able to get in Unity side as well.
So I should replace this jar in the project and I will be able to send data via push notification?
Yes, you can use Unity API to send message from your game and json must contains a message key node that message will be shown on Notification bar and the whole Json you can retrieve on Unity side.
Im confused so as to which function to call from unity to send a JSON object in push notification. Can you please help with that?
You can use any of the function
Hi Vishnu,
I replaced the jar and the push notification displays what was passed in the "message" key but now the problem is how to retrieve the other data that was sent. Which callback will be fired for this data that is sent from Java to c#?
So what kind of other data you want to send from Android native to Unity. Currently you are getting the same Json in Unity side that you have sent using API in Unity. Can you share the Json format you are trying to send from one player to other and other player is not getting the full message in Unity.
I am simply trying to send a document id along with the message. The string for sending is created as below:
string message = "{" +
            "\"message\":\"New Game Request\",\"docId\":\""+ docId +"\"}";
        Debug.Log ("message is " + message);
        App42API.BuildPushNotificationService().SendPushMessageToUser(playerId,message,new Callback());

The onSuccess Function in Callback.cs which is a part of the Push Notification Plugin, gets called but it does not print any message on the log that is useful to me.
Also there is some issue when the user registers for Push Notifications on the device. The first time it registered with my Name which I dont understand where it got from as the user id was set to the fb id of the person. The next time i ran the app and tried sending the same push notification it gave an error stating that there was no user by that name. I logged into the Shephertz app and saw that the username had now changed to the FB Id that the user was registered with. Any idea why this is happening.
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
...