Is there a way to know that a user has clicked on a notification when the application is in the foreground?
I need to send analytics for when users click on the notification and I need to know when they have clicked it.
I can't put the analytics in the destination activity as I have other analytics that are sent when the user gets to that screen. I need to know that a user has specifically clicked on the notification to open the destination activity.
For example is there a callback for when a user clicks on the notification?
Thank you
you should .setContentIntent(pendingIntent) in NotificationCompat.Builder
and put into this intent variable, then, on app start, you should check if this variable exists in intent of destination activity and if it is true, send analytics
if it is what you want, i can give code sample
Related
im beginner of using FCM to make notification in my android apps. I successed to make notification with FCM in my android apps but when i did not open my apps and there was a notification and i clicked it, it cannot intent to specific page should be, it just show the main page of my apps. But when i opened my apps, and then there was notification and i clicked it, it show the specific page. Even though, i have make my apps always running in backgroud. What is the problem? Can i make my apps intent to specific page should be although im not open my apps? Please help..
Thankyou...
Yor MainActivity is entry point of your app, so if your app not startup, click the notification will invoke it first, if you want to jump to spefic page, you should add some jump flag to your notification message body, so when the mainactivity startup, you can check the flag and jump to correct page.
I'm currently trying to find out, how to specify the destination activity on click on an android notification - but not until actually clicking the notification.
I have the following use case: I have an app where the user has to log in before using it. So if the user receives a notification from my app while he is authenticated and using the app in foreground, a click on the notification should lead to lets say ExampleActivity. But if the app is in background and a notification is received, a click should redirect to LoginActivity, where the user has to authenticate first.
Since the destination activity is specified when creating and setting the Intent to the NotificationCompat.Builder, I have no later control over the destination activity.
So if the user is logged in and receives a notification, closes the app and clicks on the notification, he gets redirected to ExampleActivity, even though he would have to log in beforehand, which is a security flaw for my process.
I feel like, there should be a common approach on how to solve this kind of problem. Is there a possibility to check if the app is running during click on the notification and decide where to redirect the user to?
Is there a way to get the list of notifications of my app?
I need to list them and let the user to delete them one by one, but I can't find a way.
I don't believe that you can list your notifications that have been shown. If the user wants to clear a notification from the app then all they need to do is pull the notification draw down and swipe it away. You can have your app cancel a notification using the NotificationManager by supplying the id of your notification to the cancel method.
If the use clicks the notification you then have two options for clearing.
1) When creating the notification you can call Notification#setAutoCancel(true) and the notification will be automatically cleared when the user taps on it.
2) Pass the notification id as part of the PendingIntent with the notification then you can use this to cancel the notification when the user taps on it.
I have a background service setting up a notification in Android's status bar. The background service is doing some work, but needs to stop when the user clicks on or cancels the notification.
I am able to stop the service, if the user clicks on the notification by passing an intent to the notification when creating it.
Is it possible to react if the user cancels the notification? Or if all notifications are canceled? If so, how?
NB: I define cancel as removing the notification by swiping to the right on it, or clicking on the x at the top right to remove all the notifications.
Check out the deleteIntent of the Notification:
The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button.
For a given Notification ID is it possible (using standard android packages) not to set a notification if there is an existing notification from the app ?
I have a news application notifying users on breaking news headlines, one of the requirement is not to over write a breaking news if the user has not cleared it or has not clicked to view it.
Im using a SharedPreference to set a flag to figure out if Im already showing a headline plus a delete intent that'll clear it. However the deleteIntent isn't always invoked when the user clears all notification.
Thanks in advance.
Sandeep
For anyone following this later:
There's no easy way to not to overwrite a existing Notification ID using the SDK. The way to do this is:
use a boolean flag via SharedPreference, if this flag is set then don't write the notification
reset this flag when the user "Clear"s all notification. To do this setup a deleteIntent (via a Service), make sure you clear this flag in the onStartCommand() and onStart()
optionally reset the flag when the app is launched
If your requirement is :
one of the requirement is not to over write a breaking news if the user has not cleared it or has not clicked to view it.
You can use NotificationManager for getting list of all the active notifications posted by your application using getActiveNotifications()
And check if the user has dismissed or opened the notification and take the required action.
As per the reference doc for getActiveNotifications():
Recover a list of active notifications: ones that have been posted by the calling app that have not yet been dismissed by the user or cancelled by the app.
Hope it helps.