I'm developing an app using Ionic 2. This app must receive push notifications. The notifications are sent with GCM and received with Ionic 2 Native Notification plugin.
When the app receives a notification it saves the notification in a database.
When the app is open the notifications are received, saved and shown in the screen.
When the app is in background I receive a message in the notification area of the system and when tap this message it leads to my app and the app receives the message, saves it and show it.
The problem: When the app is in background, if I not tap the message in notification area and open my app the notification is not received by the app. And if I close the message in the notification area of the system by swaping it to the side the notification is lost.
My question is, how can send this notifications directly to the app? Need I change something in the backend/GCM or in the front end?
Edit.:
By adding 'content-available:1' now I don't need to touch the notification to to receive it. Anyway I still need to open the app to make it receive the notification.
This is my push message from GCM.
{
"delay_while_idle": true,
"priority": "high",
"data": {
"content-available": "1",
"some_data": "Some data",
"other_data": "Other data"
}
}
Related
When Android App is in Foreground State, onPushNotificationReceived listener is getting invoked having the notification data. When in Background or Terminated State, Notification does get received but onPushNotificationReceived listener is not getting invoked neither automatically nor when I tap on the notification. I'm sending the push from Azure Portal.
{
"notification":{
"title":"Notification Hub Test Notification",
"body":"This is a sample notification delivered by Azure Notification Hubs."
},
"data":{
"property1":"value1",
"property2":53
},
"priority": "high"
}
I'm following Tutorial: Send push notifications to Android devices using Firebase SDK version 1.0.0-preview1 (Current SDK) tutorial.
https://learn.microsoft.com/en-us/azure/notification-hubs/android-sdk
Android OS: 11
Is there something else which i need to do apart from the mentioned steps in the above link?
Make sure your app is in the background or closed then a notification message is shown in the notification center, and any data from that message is passed to the intent that is launched as a result of the user tapping on the notification.
When the intent is launched you can use the getIntent().getExtras();
onMessageReceived is provided for most message types, which follows
Notification messages delivered when your app is in the background. The notification is delivered to the device’s system
tray. A user tap on a notification opens the app launcher by
default.
Messages with both notification and data payload, when received in the background. The notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
Refer Handling response & Push notification in android to implement in your project.
You can use the .getInitialMessage() on FirebaseMessaging instance
FirebaseMessaging.instance
.getInitialMessage()
.then((RemoteMessage message) {
if (message != null) {
Navigator.pushNamed(context, message.data['view']);
}
});
Refer here
I am using react-native v0.61.5 and latest versions of react-native-hms-push (App) and hms-push-serverdemo-nodejs.
My server app is able to send both Notification Messages both Data Messages.
What is unclear to me, is how messages must be implemented in order to have this:
when app is in a killed state: a messages is received, sounds on and a bubble appears, the user taps on the notification bubble, the App processes the notification payload while opening
when app is in a killed state: a messages is received, sounds on and a bubble appears, the user opens the App without tapping on the notification bubble, the App processes the notification payload while opening
when app is in a background state: a messages is received, sounds on and a bubble appears, the user opens the App without tapping on the notification bubble, the App processes the notification payload while opening
when app is in background state: a messages is received, sounds on and a bubble appears, the user opens the App without tapping on the notification bubble, the user opens the App without tapping on the notification bubble, the App processes the notification payload while opening
when app is in foreground state: a messages is received, sounds on and a bubble DOES NOT appears, (there are no bubbles to be tapped), the App processes the notification payload suddenly
We encountered some difficulties to satisfy all these 5 requirements listed above. What we have to send from server-side? Data Messages or Notification Messages?
We also tried to use:
let message = {
notification: {...},
android: {androidConfig..., notification: {foreground_show: [false|true]}},
token: new Array(pushDeviceToken)
};
both:
let message = {
data: notification,
android: {androidConfig..., notification: {foreground_show: [false|true]}},
token: new Array(pushDeviceToken)
};
But is seems that there is no the best option...
One more thing: it seems that foreground_show does not works for Notification Messages, when I keep the App in opened state and send a Notification Message with foreground_show: true, no bubble appears and the notification is not processed by the App.
The cause could also be a bad configuration on the App side. It is not very clear how to configure it, since we are new to HMS Push Kit.
Update
If the App is in a killed state, the push Data Messages notifications may cannot be received. If you do need to use the data message, you can apply for the Special Permissions of High-priority data messages.
But at the same time, the application conditions are strict, and it may difficult to pass.
Notification Messages can be triggered only after a user clicks the notification.
Therefore, For the "Notification Messages are not automatically processed by the App if it is in foreground state" scenario you mentioned,It is recommended that you first use the server interaction to cover the foreground scenario. If a message cannot be processed due to application in the background or Kill-State, use Notification Messages.
when app is in a killed state: a messages is received, sounds on and a bubble appears, the user taps on the notification bubble, the App processes the notification payload while opening
In common notification messages, you can choose Message > Notification > data to set the customized parameters (payload). When an application is opened, the onNotificationOpenedApp event can be invoked to obtain related content.
when app is in a killed state: a messages is received, sounds on and a bubble appears, the user opens the App without tapping on the notification bubble, the App processes the notification payload while opening
It is recommended that the app obtains related information through the connection to the application server when the app is started and clears existing notifications when the app is started (a native Android function).
when app is in a background state: a messages is received, sounds on and a bubble appears, the user opens the App without tapping on the notification bubble, the App processes the notification payload while opening
It is recommended that the app obtain related information through the connection to the application server and clear existing notifications during startup (a native Android function).
when app is in background state: a messages is received, sounds on and a bubble appears, the user opens the App without tapping on the notification bubble, the user opens the App without tapping on the notification bubble, the App processes the notification payload while opening
Same as the previous question.
when app is in foreground state: a messages is received, sounds on and a bubble DOES NOT appears, (there are no bubbles to be tapped), the App processes the notification payload suddenly
You can perform the configuration by referring to the following guide:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/android-fgrd-show-0000001050040126-V5?ha_source=hms1
I am seeing how Huawei Push Kit works in Android. For this I am using postman to send the notifications, I am sending a notification message and a data message. Notification messages are seen in the notification area, but I can't get the data that I sent in the data message. I would like to know how to get them both when the app is in foreground and background.
You have to include "foreground_show": false to get the message "data" payload to get delivered to "onMessageReceived".. otherwise it will only be displayed in the notification area .. and you wont be able to read the payload..
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/android-basic-receivemsg-0000001087370610-V5
Read "Receiving a Notification Message" Title in the above doc
There's a difference between HMS Core Push Kit and FCM. Notification messages will be delivered to the system tray, and data messages will be delivered to the onMessageReceived method by default when using HMS Core Push Kit. So notification message title and body cannot be obtained.
If you want to pass data to your app when sending notification message, you can tap the notification message to trigger the corresponding action such as opening the app, a web page, or a specific page in the app. To obtain data with customized actions, see docs.
For the data message parameters, see this:
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": [
"pushtoken1",
"pushtoken2"
]
}
}
and get the data with the onMessageReceived() method.
When you send a push notification without explicitly setting the value of the *message.android.notification.foreground_show = **false***, the data content won't be read because the NC (Notification Center of Huawei phones) takes care of the notification (when your app run in the foreground).
The NC doesn't implement the method of reading the data content as stated here by Huawei.
Therefore, you have to instruct your app, so that is your app handling the push-notification rather than the NC.
To do so you have to:
message.android.notification.foreground_show = false in the payload (See here)
You need to declare the implementation class of HmsMessageService in the AndroidManifest.xml file of the app (See here).
Here you can find all the details about the payload of a Downlink Messages
I am attempting to create an app that sends notifications to user while it is not the current app or open in the recent apps. I can create an application that sends notifications when the app is open, but cannot keep it going when the app is not the current app. I have attempted to use services but to no success. Any help is great.
I am testing my program on Samsung Galaxy A 50, running Android 9 Pie. I wish for my application to send notifications at a repeating time using AlarmManager. I am trying to use the service class to allow for notifications to be sent to the user while the app is closed
it seems you are receiving notifications while your app is in foreground but not in background or killed state.
Here is a quick suggestion, Instead of sending notification with "notification" keyword try to change this to "data"
Example:
{
"to": "device token"
"notification":{
"title":"Title",
"body":"Body"
},
"priority":123
}
Change to this:
{
"to": "device token"
"data":{
"title":"Title",
"body":"Body"
},
"priority":123
}
onMessageReceived is provided for most message types, with the following exceptions:
Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.
Messages with both notification and data payload, when received in the background. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
Source: https://firebase.google.com/docs/cloud-messaging/android/receive#sample-receive
In Android APP, I have already use FCM to receive Cloud Message, when the app is foreground , the MyFirebaseMessageService.java (I defined) runned. However when the app is background or not running ,The MyFirebaseMessageService.java doesn't run, I can also receive notification, when I click the notification, Where can I get the cloud message?
Send your push as data and not as notification, and it will be received always in MyFirebaseMessageService onMessageReceived.
https://firebase.google.com/docs/cloud-messaging/concept-options