How can i check if app is opened using push notification in unity ?

0 votes
if app is opened using push notification in unity , then i need to fire event. Is there any way to do this thing.

I mean i need to check wheather  the app is opened through notification or not. I need some flag that gives me the app is opened using push notification tapping

Thanks
asked Apr 7, 2016 in Android by jns7309 (10 points)
edited Apr 7, 2016 by jns7309

1 Answer

0 votes

Hi JNS,

You need to modify plugin source for that handles such kind of thing and also change in Unity side as well.

You can try the alternative in which you can make validation on last message if its similar to the previous one then its is not opened using Notification else it can be.

we have provided the specific function getLastMessage on which you can apply your logic.

Let me know if it helps.

 

Thanks

Vishnu Garg

answered Apr 7, 2016 by Vishnu Garg (674 points)
Hi thank you very much for you valuable answer.
Got success when app is open and app is running in background.
But want last message that was received in notification.
Problem is that when app is closed i am receiving notification in unity android/ios device.After tapping the notification app is opening.  I want to take some event on using that opened notification.
If there is any code need to integrate in android manifest file or it can be done with using last message function then give me some idea or code.

I want just redirect using opened notification data




Thank you
After tapping Notification you can open the Activity, We have an API that will return the last message in Android you can make validation on that, if it is same as the last message or its a different one.
yes, But i am making a multiplayer game and using notification I want to redirect  player to particular room when he taps on notification.
I can check last message but we also need to redirect when message is same, i don't need to compare last massage in my case. I need to  open the Activity means join room name on notification room name(passed  message in notification).  I want to call  OnMessage fucntion when app is opened using notification tap. Hope you are getting me
Please tell me which api that i need to modify.

Thanks
Ok, than fine you just redirect the player. getLastMessage API is already implemented in the plugin. You need to write code in App42GCMService.java file that will do validation if application is already opened no no need to show Notification.
yes getting it.
but what to do in case when app is closed and also not running in background.
and at that time when i receive notification and tapping on it, want to call on message function. Or is there function like onNotificationOpen ?
Stucked on this.

Thanks bro
Actually when Unity application is closed and you tap on the notification message is received by getLastMessage function.Native calls that function when push receives as application is not running it throws the exception.
So by the time you can write code in that Catch method that will show the notification.
Sorry but need some more help.
Should i check in this function.
If you know Execeptional code to call notification then can you please write ?


public void onPushNotificationsReceived (String message)
{
    if (app42Listener != null && message != null)
    {
            app42Listener.onMessage (message);
    }
}

Thanks a lot
I have make a changes in plugin, please download the same http://cdn.shephertz.com/repository/files/0b26c41b452832e42f606729ccb33be33103cc16898fa73d9db2ad6415fc589e/857bbb01ea34c040d99215646f9a0f730b016564/app42pushservice.jar

and replace it in assets folder.
In App42GCMService.java class I have make these changes.

try {
                    App42UnityHelper.sendPushMessage(message);
//Earlier message is shown first
                    sendNotification(message);
                } catch (Throwable e) {
                    Log.i(TAG, "Application is currently closed");
                }
ok thanks a lot.  Its working for when app is open is I am not receiving notification.

But to open closed app and getting last message using
Aapp42Push.getLastPushMessage(); Not working.

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.

What to do when app is closed and get last message when I open it ?

thanks
thanks for help

file replaced with app42pushservice file.

Getting last message when app is closed and opening it. But does not getting any notification when app is not running. And also app crashing when app is open and sending notification.

Don't getting why app is crashing and not receiving notification when app is not running
thanks bro

Replaced file.

But still getting same issues. tested in two android devices. In Samsung tab(android 4.4.2) app does not crashing and in moto g(android 5.0.2) its crashing.
And still does not getting notification when app is closed , just receiving last message.
Will you please share the crash logs, so that I will handle the same in custom plugin.
thanks for answer
Here is captured log , when app is crashing after sending notification

http://www.filetolink.com/e00284b307

May be it can help to you
hi good morning
is there any luck in get last message and app crash issue ?
Will you please share the logcat logs, that will help more.
this is the log that i have got while runnign APK file in device , and when its getting crash when push notification arrives.


W/ActivityManager(  946): getTasks: caller 11169 does not hold GET_TASKS; limiti
ng output
W/ActivityManager(  946): getTasks: caller 11169 does not hold GET_TASKS; limiti
ng output
I/ActivityManager(  946): Process com.test.push (pid 20475) has died
W/ActivityManager(  946): Scheduling restart of crashed service com.test.push/co
m.shephertz.app42.push.plugin.App42GCMService in 1000ms
W/ActivityManager(  946): Force removing ActivityRecord{2c511921 u0 com.test.pus
h/com.unity3d.player.UnityPlayerActivity t1125}: app died, no saved state
I/ActivityManager(  946): Start proc android.process.acore for content provider
com.android.providers.userdictionary/.UserDictionaryProvider: pid=20774 uid=1001
6 gids={50016, 9997, 3003, 1028, 1015, 1023} abi=armeabi-v7a
W/ActivityManager(  946): getTasks: caller 11169 does not hold GET_TASKS; limiti
ng output
W/ActivityManager(  946): getTasks: caller 11169 does not hold GET_TASKS; limiti
ng output

I used this link for android unity  debug.
http://answers.unity3d.com/questions/492681/how-to-use-adb-logcat.html

Hope it will help
You can use only "adb logcat" command that will do the complete logs. Actualyy I want to know the line number where application is crashing.... Or you can send me the apk file as well.
Hi..

Here is Unity sample code,APK file,shephertz acc credentials(in doc file) to test apk.
Download link

https://we.tl/dP35awJxIp

apphertz account link To send notification using credentials :

https://apphq.shephertz.com/service/index#/pushUsers

thank you
hi

Getting last message every time successfully.
 But
When Tested it with multiple android device, in some devices(with latest android devices os) its crashing and devices with older android os doesn't crashing.


When app is closed and then we send notification its shows unfortunately stopping message like below link and doesn't display any notification on notification bar.

http://postimg.org/image/vvwfq8w29/.

Here happening vice versa things, when you gets notification, we doesn't  getting last message when app is not running. And when we are getting last message then we are not getting any notification.

If you have successful demo for android unity that works with push notification and getLastMessage method when app is quit, Then please give me link of sample code.


thanks a lot bro. Please help
Please don't build the same in latest android version 6.0 API Level 23, as it requires run time permissions.
As your previous query I have disable the notification if application is running..
How you are checking getLastMessage function if its not running.
Hi,
I hearty appreciate the helps you are doing me for this task.

Somehow, the things are not going through. Let me summarize what's currently happening for me.

1. Push notifications :
- When game is active : It works OK.

- When game is in background : We do receive push notification.
In this case, I want user to tap on this notification & go directly to one of my screen - lets say 'Screen#1'. But this is not working somehow.
If I tap on the notification when game is in background, it is not driving me to desired screen.

- When game is closed (not even in background) : Presently, we are not getting any push notification in this scenario.
Additionally in Moto G device (OS 5.0.2) - when push notification is fired from App42 server, on device, it gives me error "Unfortunately app stopped working".

- For the devices running on lower than OS 5.x -- New problems that we observed are - Now we are not getting any notifications on these devices.
Earlier (before I got updated files), these devices were getting push notifications.

- Earlier before - we were not getting the message extracted out from Push notification. But after using New files that you gave today, I see possibilities of getting the message extracted from push - but to do that, we must get push notifications (which are stopped at the moment). So in case if you can fix the issues related to get push notifications - I hope we can overcome to all of your issues.

So mainly I'm seeking help or instructions on how to overcome these situations.

In case of any confusions, please feel free to ask me.

Thanks a lot.
How you are checking getLastMessage function if its not running.
==> When the app is not running, I would need two things. First is to receive the push notification & second is to get the message.
I have added two libraries in it :
Lib 1 : Check the app and show notification if not running
Lib : show notification always

Also provide the permission that checks the status in manifest.xml file
<uses-permission android:name="android.permission.GET_TASKS" />

  http://cdn.shephertz.com/repository/files/aabd1c3e3500919cbefbd0fa6f0e41ebc0bd6722d59b86ecf3b518d6bc1b8e25/0eefdafbef06a39f18b759721ab02c73d1e451ee/Test.zip
hi
I have tested both file replaced one by one with setting
 <uses-permission android:name="android.permission.GET_TASKS" />
 , then what i get result is:

when using

Lib 1 (app42pushservice1 file):

- Doesn't getting notification if app is closed or open.
- Getting getLastMessage when app is open, doesn't getting last message when app is closed

Lib (app42pushservice file) :

-Doesn't getting notification
-Doesn't getting getLastMessage
-Doesn't calling OnMessage Function

Thanks again
I am little confuse how you are dealing with getLastMessage when application is closed.

Let I do complete testing first and let you know .
1. Dont show Notification when application is running.
2. Show Notification when application is not running.
3. getLastMessage when your unity application is restart or open.

I will update on the same once I do the testing, meanwhile if you you want to customize plugin based on your use cases.
Hi
Gm.
Have you got any success in above  mentioned points ?
Hey, We will update on the same on upcoming Monday after modifying and testing the plugin based on your requirement.
Mean while you can also modify the plugin logic I have make a modification on plugin but not tested with all the testcases, You can use the same and mark the point on the same.Please find the link .
 http://cdn.shephertz.com/repository/files/1236b99b5930a6d469c4a1dd426d380e3875b8a9b1947177ab0cf813225ee234/7469d52c41e5dd85ee17292f436767d90265b6bc/app42pushservicenew.jar
Hi..
Hope  you are doing well
We have tried to accomplish our requirement and also made changes in pluging but did not got what we want.
Hope you have found some solution.

Thanks
Hi,
Please download the same from
http://cdn.shephertz.com/repository/files/9b4bc0d2fcbdb52ad04dcb4cb2f9c9d95c80a4c7893196cd57ab483aa3087621/27be0bec13c6a746b420f590534d1bb5b0ed7d58/app42pushservice.jar

I have tested the following scenerio
1. If application is open then it will save the message and notification not shown.
2. If application in pause or background shows the notification and save the last message.
3. You can also send as json like
{"message":"hello","gameData":"test"}
It will show the value of message node hello in UI Notification and you will get all message in getLastMessage function.

Also add the permission in AndroidManifest.xml file if not added.
 <uses-permission android:name="android.permission.GET_TASKS" />
hi.. good morning.
Thanks a lot for valuable reply. Its working as we want.

Can you please help on these two points:

1.This thing is working in android, What should I do with iOS ? If there is some change in App42PushHandlerInternal.h/.m then let me know to do this.

2. Is there any method or way to clear getLastPushMessage() ?

thanks once again
Hi,
On iOS, if app is open you will not be able to see the push notification by default as per the iOS behavior.
Also, the iOS plugin does not store the last message as of now, so there is no need to clear it from plugin side.

Let me know if you have any other queries.
Thanks.
hi
thanks for answer.

there is still some confusing points
1.
But what should i do to receive last message in ios ? or is there any other option that replaces getLastMessage function. So i can redirect from notification bar to specific screen.

2. in android  system, how can i clear last message ?

My main concern with the notification is that  , i want to redirect using notification to specified sceen, to do this i need some event or data. so i am using getLastMessage.

But i think this is not possible using getLastMessage for ios.

If have any demo or reference of notification redirection then let me know.


thanks bro
Currently we haven't have any demo for your requirement, But you can modify the same based on your logic.
Thanks for answer

 But if i want to open specific screen when we tap on notification, how can i create activity in unity ?
Please let me know  for this.

thanks
Generally Unity have only one Activity name as UnitPlayerActivity, It actually loads the first Screen of Unity while tapping the Notification, where you can write logic of Screen or scene switching based on the last message you will get.
yes right ,
I will get always last message, and i dont want open screen every time. As I am getting lastMessage every time, and this  thing is not right.

thanks for answer.
So Again on Unity side you need to save a variable that validate the status of screen open against that message
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
...