Unity Android - Opening Unity Into Scene From Push Notification, Retrieving Data From Push Notification

0 votes
Side note: I usually put the category as Android when asking a question because there's only one Unity Android, but the Unity category can be either iOS or Android. 1. I'm looking to find some information on how to open up a specific scene in Unity after tapping a received push notification. I know this has to do with the manifest file and something regarding either com.unity3d.player.UnityPlayerActivity or .MainActivity. I just have absolutely no idea how to implement this. I need to find a step-by-step explanation. 2. If I can achieve #1, I'll need to somehow receive data from that push notification. I also have no idea how to do this. I noticed that I can send what appears to be a JSON string, but I wouldn't want a JSON string to be visible when received by the user. I hope my questions were clear enough. Thanks in advance for your help.
asked Mar 16, 2016 in Android by null (23 points)

1 Answer

+1 vote

Hi,

Yes, You can achieve this by making the validation while opening the main Scene based on last message.

  • Whenever application opens, you can fetch the last message.
  • If message is available you can make validation on that and can switch to specific scene accordingly.
  • You can use the message data on the next specific scene that you have opened.

Let me know if it helps.

Thanks

Vishnu Garg

answered Mar 17, 2016 by Vishnu Garg (674 points)
Okay, I can get the last message that was received while game was open using App42Push.getLastPushMessage() and it even updates in real time, but I cannot seem to retrieve the message from the push notification that I received while game was closed.

I have App42Push.getLastPushMessage() running on Start() and it just retrieves the last push message I received while the game was open.
Unity only receives the last push notification that was sent while game was running.  It doesn't receive push notification messages from push notifications received while game isn't running.
In other words, if I receive the notification, 'Player two defeated you!' while the game isn't running, then click on the notification, when Unity opens, it only shows me the notification that was received when I had Unity open.

I need to transfer the notification message that I tap on (the one that opens Unity) to Unity.
At this case you need to modify plugin source accordingly based on your requirements like
> You can save message on local preferences based on type.
> Which message you need to send when push is clicked
How to store that preference in unity android ?
Is there any function that calling when i opening app through received push notification ?
I am getting message from onMessage function, but i want to check through when i open app using notification

Thanks in advance

Please help.
You can use unity preferences for that, or in Android you can modify the existing plugin to save more details. You can make validation on getLastMessage function if it is opened by Push. When application opens by click validate the same, and save it locally for further validation on next time.
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
...