Persistent Notification Message with switch (ON/OFF) on Android/iOS? - android

I have a mobile app implemented in React Native where the user has a status online/offline. I want to implement a persistent notification message that shows up whenever the user status is Online, even if the app in the background.
I know that there is a possibility to do actions within notifications like pause button in the media player apps. How could this be done in react-native?

Use https://github.com/zo0r/react-native-push-notification
If you want to make it sticky you can set :
PushNotification.localNotification({
ongoing:true
)}
You can use ongoing property of this library to make sticky notification

I'd look into https://github.com/testshallpass/react-native-dropdownalert I think it would offer exactly what you need

You can use FCM for push notification.
Package details :
https://github.com/evollu/react-native-fcm
First you need to store user vise device token into your database. Then if user's status changes to online you can send FCM notification to set of device tokens or just one you set. So notification will pop on your device.
Hope this is what your are looking for.

Related

How to control whether to display notification or not based on the screen that is being displayed in android studio?

I am making a chat application and I am using Firebase Cloud Messaging to send push notifications. Everything is working fine but I do not want to display notification if the app is already in chat screen. I am using jetpack compose for UI and have single-activity architecture.
So in my chat screen, I don't want to display the notification. However, if the user is at other screens, I want to display the notification.
How can I achieve this?
There can be two possible solutions
Declare boolean in Activity or SharedPreference and toggle value according to lifecycle event's.
Once you receive firebase notification send broadcast and listen in activity. Inside activity identify top most visible screen using navController like below and decide wheather to show notification or not.
val visibleScreenRoute = parentNavController.currentBackStackEntry?.destination?.route?.split(Constants.KEY_QUESTION_MARK)?.getOrNull(0)
Hope this will help you to solve the issue.
I have the same case as you.
First, you need to create a custom notification and control push notifications manually.
Second, you have a module which checks whether activity is displaying or not.
Finally, when you receive notification data from firebase, using above module to decide display notification or not.
Check this document for more details : Build Notification

how to open a app when its in quit state while receiving fcm push notification - REACT NATIVE

Planning to build an app like uber we have two apps one for end users other for drivers, if end users send a booking notification we need to display in driver app push notification as 'cancel' and 'accept' button with sound like ringtone or we need to open the app automatically, if the app is in quit state or background state. Technologies used: - react native, firebase. Please help me to resolve and am eagerly waiting for your valuable suggestions and ideas
https://0x1bitcrack3r.medium.com/incoming-call-notifications-for-react-native-apps-ef4725702401 - using this blog i can able to change the push notification ui and able to trigger ringtone like whats app call
i would suggest you to go for https://rnfirebase.io/ using this you can have an node app or use firebase function to push notification to the device which is registered
here you would use the following
onNotificationOpenedApp
:
When the user presses a notification displayed via FCM, this listener will be called if the app has opened from a background state.https://rnfirebase.io/reference/messaging
onNotificationOpenedApp(listener: (message: RemoteMessage) => any): () => void;

Choose to show or ignore push notifications client side?

We want to send push notifications in Android and iOS to a group of users that match a certain condition. We can check if an user match this condition calling an API.
Our problem is that the users information changes very quickly and we don't have any way to keep track of this in our push notifications engine (OneSignal).
The only alternative we can think is to send the push notification to all users and client side call the API to get the latest user information. Depending on this we could choose to show the notification or ignore it.
Is this possible on Android and iOS?
It is 100% possible for sure. in the receiver class you call an intentservice, which can hit an api and get the latest information, based on the information you create notification using notification builder, and avoid if you dont want.
Yes, with the help of NotificationExtenderService this is possible.
Receive a notification in the background. Notification data is wrapped up in OSNotificationReceivedResult object. Now, read the notification id/title which should be unique for every notification.
Send this unique notification title/id along with user id to an API, which will return whether to show the notification to the user or not. If true then read notification title and message/description from OSNotificationReceivedResult and make a notification via NotificationCompat otherwise just ignore it.
Reference

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.

Can we perform an ACTION programmatically on a Notification from Notification Listener Service?

Is it possible to invoke an ACTION programatically on a Notification from a NotificationListenerService?
I have written a Notification Listener service that reads out all the incoming notifications and dismisses when done. But I'm not sure if we can perform any ACTIONs on the incoming notifications.
For eg: On a WhatsApp message notification I can read the package name, sender and message details but is there a way to send a reply back to the sender?
Currently Android Wear is doing this so I'm wondering if it is following a generic approach of acting upon a Notification or it has a specific API to WhatsApp service.
When ever a whatsapp notification is received via notification listerner service there is one another notification thats received (hidden) which has a tag value something like this XXXXXXX#s.whatsapp.net (xxxxxxx being the phonenumber), I think this somehow holds the key to sending a reply to this user.
I am working on other app logic, which does not require you to send back replies but I found this interesting but could not get enough time to check it myself.
Yes, you can do it by this function:
sbn.notification.actions[0].actionIntent.send()
Yes, we can perform actions on notifications. Pushbullet app on Android has an ability to reply to WhatsApp, Hangouts, Facebook messenger etc when user enters the message form desktop which means that there is a way. I am still trying to figure out how to do it.

Categories

Resources