How to tell app was started by tapping push message notification - android

I have a Worklight app that receives push notifications from the server. A notification means there are new messages for the current user from other users. A user would read them by visiting a messages page within the app and then proceeding to a particular conversation page.
I would like to differentiate in the code between user intentions. The app would:
If the user started the app normally (not by tapping a new notification), present the user with the regular app home screen.
If the user started/resumed the app by tapping a notification, present the user with the messages page.
If received while the app is on foreground, only update the on-screen message count (regardless of which page is active).
The question is: is there a reliable means to differentiate between the above conditions?
In another thread, I saw a suggestion to remember the timestamp of a resume event and an onReadyToSubscribe event and assume we were asleep/inactive if notification arrives e.g. just a second after this. This would enable me to differentiate between 2 and 3.
However, 1 is not covered by this. I.e. if there have been new messages, but the user started the app normally, the app would have no means of knowing this and would think it was started by tapping a notification. This way, the user intended to see app home screen, but we transfer him to the messages page.
Is there a reliable way around this for both iOS and Android?
Worklight vesion 6.2.0.00-20140922-2259.

In a pure Native application, you can know "where from the user opened the app", meaning whether it was by tapping on a received notification or by tapping the application icon.
In a Worklight-based Hybrid application, and if using only the JavaScript API, this is not feasible because all paths arrive to the same destination which is the pushNotificationReceived function. So whether you tapped a notification or the app icon or brought the app to the foreground, the aforementioned function will be invoked.
The solution may be to base your implementation on the following Knowledge Center documentation topic: Using native and JavaScript push APIs in the same app.
This way, using a combination of native code and JS code, you could handle the scenario where a notification was received but the user decided to tap the application icon rather than the notification.
An end-to-end example would to somewhat involved to implement, but if you'll follow the code examples in the documentation topic, you should get there...

Related

Why do Android Push Notifications call Application create and trigger AppStartup

I have noticed that when I send a push notification (Firebase Messaging Service) to my device my Application object is created. This is without clicking on the notification. Simply the act of viewing the notification creates the application. Further, it also starts the Jetpack AppStartup library. I want to be able to use AppStartup and application create. But I don't want to launch that code when a push notification occurs.
Why does Android do this? Is this part of all android notification, or is it a feature of the third-party push notification sdk I am using? And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
Again, I'm not talking about the user clicking on the notification (and launching the app because of a deeplink). I'm talking about just looking at the notification in the notification dropdown.
Why does Android do this?
Android is starting your app process to run code in your app. Creating an Application instance and calling onCreate() will be part of that, as will creating any ContentProvider objects. IIRC, Jetpack Startup uses a ContentProvider to get control early in your process, though I am not 100% certain of that.
The reason why Android is starting your app process is because your app is causing the Notification to be displayed — specifically, Firebase Cloud Messaging is doing that. If I remember the protocol correctly, Play Services is sending a broadcast Intent that Firebase Cloud Messaging in your app will respond to, and part of that code will be displaying the Notification.
And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
onCreate() of an Application subclass has no means of knowing what specifically caused the process to be created, as there can be many possible reasons. If by "AppStartup" you mean Jetpack Startup, I do not recall it having any options here, but I have not spent much time with its API.

Force IOS/android user to check the notification

I am developing a IOS/android app which will used by our vendors, the app will send notifications to the vendors timely, i wonder if there is a way that the vendor MUST click "accept" or "read" for every notification, even he/she disable the notification permission for this app.
so, all of my perpose is the vendor must ready the notification and the server side should be able to know who is not read. the vendors should not has an execuse that he/she do not get a notice while the policy changed.
There is no way to 'force' a user to open a notification, but if you use a Push Notification service (AppBoy, etc) most of them have metrics and can track who has opened the notifications. So if your vendor comes back and says they never got it, you can say yes you did, and which device they opened it on. You could then continually send notifications to those who haven't opened it until they do.
This won't work if they have notifications disabled, though. No way to get past that without building a messaging system into your app.

Know if the app received the notification from server side

I'm building a newspaper-like app and I would like to know how many people received the article's push notification vs how many actually read it.
I was thinking to implement a way in which when the notification is received the app wakes up and send a request to the server saying "Hi I'm _____, I've received the notification of the article ____" and store it in the database. Then afterwards if the user click on the notification and goes to read the article I send another request saying "Hi I'm ____ and I've read the article _____" and I also store it on the database. Afterwards with some queries I'm able to understand the percentage read/received.
I don't understand if it's even possible to wake up the app even if it was not opened by the user in a while and send a request to the server (for background is meant that the application is not launched or that is in the cache ?).
I would like to achieve what they did with Whatsapp:
I receive a new message on Whatsapp
I don't open the app
I go to WhatsApp Web
I open the conversation on WhatsApp Web
The badge and the notification on the phone goes away because I read it somewhere else
I think that that feature is achieved with silent push notifications that just update the app badge and clear the read notification.
Thats a very nice question on how to implement such silent notifications. There are few variables here that we need to consider and deal them in a different way.
Push notifications sent to the users - Some of them would have received it, Some may not have received it at all.
Pushing multiple notifications to the same user in a small amount of time - It becomes difficult here to track the exact notification user opened the app. Because user might have read all the news that received notifications in a single attempt.
The actual content displayed to the user in the app - User might have opened the app because of notifications. Some times he might have seen the notifications and then opened the app directly without interacting with the notifications.
So this is how the implementation can be.
Implement push notifications for the app
User receives the push notifications and the notification badge shows Number (1).
Now when the user views the same news story in any other medium (Your own Mac App or PC app). Server is notified of the users action and the news he/she/whoever just read.
Now the server knows it has sent a notification and it is not read. When you receive the read notification, you can send a remote notification that can be handled by the app in background and update the badge.
Check out this link for more details on how to handle notifications in various modes.
Apple documentation also can be referred here for background mode - remote-notification.
So you will be making your app run in background with certain settings to respond to silent notifications and update the badge just like WhatsApp. I hope this helps.
I've already implemented such thing in one of my app, and it's actually tricky.
You'll have a lot of use cases to handle.
First thing (but you seem to already know it): Apple does not provide
any callback to say : "this notification was sent"
Second thing : when your app is killed (not even in background), nothing at all can be done with your notification, meaning your app won't be able to wake up and read the notification, and therefor do something. The only thing you can do is changing the badge number, even if your app is killed.
Third thing : when your app is in background, you can wake up your app during 30sec. During that time you can send a request to the server, but if it takes too long, the process will be killed by the OS.
Saying that, here is a quick explanation of how you could implement the system:
You'll need on the server side to save in your data base any notifications that were sent. As soon as they are sent, save them as "pending"
On the app side: if your app is in background, as soon as the notification is received, you can wake up your app to send a request to the server. Then in your data base, your notification status will change to "receive" or "notified". If your app was killed, when the user launch your app, send a request to the server to ask for all notification in "pending" state, that way your app will be up to date, as well as your badge number.
If the user click on the notification, this will open your app directly on the article, that way you'll be able to send a request and say to your server that the article was received and read.
If the user read your article on the web side, send a notification. Set the notification badge number with the number of actual "pending" notification in your data base.
Hope this will help you in addition of the answer of #Prav :)
try this Notification Listner service https://github.com/kpbird/NotificationListenerService-Example.
Reply from Apple Developer Technical Support:
Hello Matteo,
Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.
So at the end of the games IT'S NOT POSSIBLE
You want to sync your app with web app or website than once you send notification to application than set notification to particular ID.If user read that message from your web then send push notification again with different message and handle in service or broadcast receiver after that cancel notification if received message contains different message.you can also use Notification Listener.Refer thislink
Refer this link for ios.
Hi #Smile Applications after reading your question I would suggest you see OneSignal website. OneSignal will allow you to send notifications to your subscribed users. It will also show you how many users are using your app and how many of them have received your notifications. If you want to send notifications and track them from the app itself you can use their API. It is easy and I have implemented this in Android and soon will be implementing in IOS.
Now the second part of your question about knowing how to track how many users have read/opened your notification and on which activity they are on you can use Google Analytics. It will allow you to see from which part of the world your users are using your app and which activities of your app are being opened most. It is also easy and I have implemented this also in Android and soon will be implementing in IOS too.

Get user position (gps) even if app is closed

I'm deploying an app with Ionic framework. The app basically need to receive push notifications based on (specific) user position. Those notifications are location dependant, so I'm trying to figure out if it's possibile to retrieve current user location without ask the user to run the app.
I know that push notifications are received even if app is not running, what I'd like to do is to show notifications only if the user is in a specific area.
Thanks
I know that push notifications are received even if app is not running
That's not true. Push notifications let your application notify a user of new messages or events even when the user is not actively using your application, but application must be started and running in background.
You must perform 2 different actions:
Execute app on startup to allow it to perform actions needed.
Use GPS in background to know when device is in the desired position to notify.

Air iOS/Android push notification remember when app launches

I have an app built for iOS and Android which has push notifications. Everything is working great however I was wondering if there is a way to store the data of the push notification in the app so that when users launch the app after receiving a notification I can show them the message again?
Basically I allow users to share information and/or chat amongst their friends. If they receive a notification when the app is in the background it comes through as a normal push message but when they launch the app I would like to direct them to the chat feature to see the message again.
I am storing the messages sent in a remote DB but seeing as they have already received the payload it doesn't make much sense for the app to call the remote DB to retrieve the same message.
I am using Distriqt's extensions in AS3 and Air 3.5.
Cheers
I asked Distriqt's support for the same thing a few weeks ago and they explained that there is no way to get the information of the push notification message while the app is closed so they suggested this :
- when the user opens the app, you call your server to check if they haven't missed anything, and get the data from there. If there has been a push, you display the push message as if it was received with the app in the foreground.
It's a bit tricky and not very satisfying but it works.. As long as the user follows the path.
If your user receives the push and chooses not to open your app, he will still get the push message in your app next time he opens it.
I was having trouble figuring this out too but I found a solution! Basically if a user launches an app (not running in the background) by way of a notification it comes through in the Invoke event, not the usual Notification event. So do this:
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
private function invoked(evt:InvokeEvent):void
{
if (evt.reason == InvokeEventReason.NOTIFICATION)
{
var payload:Object = Object(evt.arguments[0]);
// do stuff
}
}
That's pretty much it. There's more detail in this blog post here: http://blogs.adobe.com/airodynamics/2012/05/29/push-notifications-support-in-ios/
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
doesn't work correctly for Android push notification. Android starts with InvokeEventReason.standard all the time, so we cant receive message. It works only for iOS.

Categories

Resources