Async Notifications in react-native - android

ok so I have an app in react native which retrieves the information from an api. Now the api whenever it has data to send will send the data to the device and I want my app to be always running in background so as to receive the response from the api. API can send data anytime so I want to show the user data received as soon as a message arrives.

You need to look into Push Notifications. You can't guarantee that your app will always be running in the background, but Push Notifications allow you to send data to a user's phone even when the app isn't running. Once the user opens the notification you can perform some action, based on the data sent with the notification.
A good React Native component for push notifications is React Native Push Notification, which offers cross-platform notifications. Once you have this implemented you can create a handler which calls your API when the app is opened from a notification.

Related

Send request to an other android device in a app

I am currently trying to make a personal location application between 2 devices on Android.
The concept is simple: I install my application on my phone as well as on that of my wife and each can geolocate the other.
(This application is strictly personal)
To achieve this, I thought of using sending notifications by FCM.
Telephone A sends a request to telephone B which listens via a service for the reception of a message.
When phone B receives the request, it returns the GPS coordinates via FCM so that phone A displays them on a MAP.
(I also have the possibility to store the coordinates in a database instead of sending back an FCM message)
But FCM's documentation says:
"When your app is in the background, notification messages are displayed in the system tray, and onMessageReceived is not called. For notification messages with a data payload, the notification message is displayed in the system tray, and the data that was included with the notification message can be retrieved from the intent launched when the user taps on the notification."
Of course, this reduces the scope since it forces the user of the phone receiving the notification to click on it to activate the actions of the service.
Can FCM still meet my needs through another channel?
Are there other options to send a "request" to another phone?
(I know that this kind of application exists on the PlayStore, but I want to try to make mine :-))
The key word in that section from the documentation you quote is notification messages. Firebase Cloud Messaging supports two types of messages:
Notification messages, which are display by the system when the app is inactive - and delivered to your application code when the app is active.
Data messages, which are always delivered to your application code.
It sounds like you'll want to use data messages for this use-case

How Facebook messenger make mobile calls in background?

How does the Facebook messenger establish video calls when app is in background?
I'm making an android video call hybrid app using webrtc and socket.io, the video calls works fine with app open but I don't know the best way to contact a target user if he's not in the app, my idea is to send a push notification to wake up mobile and enter in the app and then start the video call, the problem is if target user don't allow notifications.
I've already tested calls in messenger with notifications disabled and with the app in background and the call works the same. I can't find any explanation how messenger can start a call when the device is not awake.
Is a notification or a service that allows that?
Check out Firebase Cloud Messaging, it's what most people and what Google recommends to use to push notifications. However, that doesn't mean it has to be used to send notifications and it won't be blocked even if notification is disabled. You are able to send data payloads with FCM and handle them on your client with onMessageReceived with FirebaseMessagingService. For more details, refer to the documentation.

Sending Android Notifications between app users

I am currently aiming to make an app in Android Studio that allows one user to push a button and another user to receive a push notification as a result. How might I do this?
You're going to need a server to act as an intermediary. Set up an API endpoint that your app can call to request a notification, and have your server dispatch a message to the receiving device using something like FCM.

silent push notifications in react native app

We are working on a react native app, in which we have some features where we can do some actions using silent push notifications. we are using react-native-firebase for that.
For sending push notifications we are using firebase cloud functions, here is the payload structure.
let payload = {
token: pushToken,
priority: normal,
data : {
RequestUserID : event.params.requestId,
}
We are not getting callbacks for app when its running in foreground or background ?
Any solution to get silent push notifications so that we can perform some tasks, when app is in foreground, background or killed ?
I don't think it's possible to not give an alert (unless the user disabled them) when the app is backgrounded or killed and receives a push notification. You could send data and run a task while the app is backgrounded if you use a websocket. That would not send an alert. If the app is closed, you won't be able to make it do any task.
You need to send you data in a notification payload instead of in a data payload. As seen in https://rnfirebase.io/messaging/usage

How are Android GCM push notifications processed?

I am working on a Cordova Android app that handles push notifications using the PushPlugin. The app will correctly receive push notifications when the app is open. However no push notifications are received (or at least handled) if the app is not open.
This makes some sense given that the plugin has code that specifically handles receiving push notifications. What does not make much sense to me is why this code even exists at all. Before building this app, I assumed that the OS had some sort of queuing system that received any/all notifications.
Does a notification queue exists in Android that handles push notifications for all apps or does each app need to handle the notifications on their own.
Can Android apps process push notifications while closed?
Can Cordova Android apps process push notifications while closed?
In Google Cloud Messaging (which is the push notifications mechanism used by the PushPlugin) each application decides how to handle the notification. When a push notification arrives to the device, GCM triggers a BroadcastReceiver in the recipient application, and the application is responsible for handling the notification data.
Android apps can process push notifications when closed unless they are explicitly stopped by the user (in which case no notifications will reach the app until it is restarted again by the user). If they leave the foreground by the user switching to another app or going to the home screen, the can still receive and process notifications.
Yes. According to the PushPlugin you posted a link to, it seems that they can. When the app is not in the foreground, the notification is handled differently - a notification is added to the notification bar, and when it is tapped, it should open the app.
With PushPlugin, when sending push notifications to GCM (for GCM to send them to the device) one has to include a msgcnt key value pair after the message key value pair in the payload value in the JSON message, like this:
{
"GCM":"{\"data\":{\"message\":\"hello\",\"msgcnt\":\"1\"}}"
}
or else PushPlugin will not handle the notification when the app is in the background. It has to do with the way the GCMIntentService.java file is written in the plugin.

Categories

Resources