I am using the Native Push Plugin for an Android application I'm developing. I have configured an icon and an icon color for my notifications like this:
let push = Push.init({
android: {
icon: "ic_notif",
iconColor: "#f94915",
forceShow: true, ...
If I send a notification through the Firebase console (Target = User Segment -> App -> My App) and I'm in the foreground (the application is visible), my notification icon is displayed correctly in the notification area (the icon color as well in the notification drawer). However, if my application is in the background (or not started at all) and I send a message, I get a white square instead (and the icon color in the notification drawer is the default gray).
By looking through the source code, in GCMIntentService.java, I discovered that the method onMessageReceived handles the incoming message. When I'm in the foreground, the following condition is fired:
else if (forceShow && PushPlugin.isInForeground()) {
Log.d(LOG_TAG, "foreground force");
extras.putBoolean(FOREGROUND, true);
extras.putBoolean(COLDSTART, false);
showNotificationIfPossible(applicationContext, extras);
}
The method showNotificationIfPossible is responsible of creating the notification (icon, icon color, vibration, sound, etc.). The problem here is that it seems that the code is not being executed while the application is in the background (I'm getting the message nonetheless), specifically the following code, and that's what I think it's the problem here:
// if we are not in the foreground always send notification if the data has at least a message or title
else {
Log.d(LOG_TAG, "background"); //this is not being logged at all
...
Does anyone have any idea what's going on here?. I guess I need to check the source code more thoroughly to figure it out.
The syntax of manifiest.json file has updated and there are some new things came around, pls check in below example are those same in your case ?
{
"name": "Ionic",
"short_name": "Ionic",
"start_url": "index.html",
"display": "standalone",
"icons": [{
"src": "assets/imgs/logo.png",
"sizes": "512x512",
"type": "image/png"
}],
"background_color": "#4e8ef7",
"theme_color": "#4e8ef7"
}
from this file you can do whatever ui changes you need.
Related
I'm developing an application with Kony, and I need to send some notification to user device.
If the device is an iOS one, the notification is handled right (the notification can be dismissed).
But if the device is an Android one, I'm not able to dismiss the notification from the notification center by swiping it and this is really frustrating for the user experience.
This is the JSON I'm sending to GCM:
{
"notification": {
},
"data": {
"notifyData": [
<some app related datas>
],
"title": <notification title>,
"description": <notification body>
},
"registration_ids": [
<device registration id>
]
}
I've tried setting on "notification" block either "ongoing" and "autoCancel" flag, but nothing change.
How can I let the notification be dismissable?
Please go through with the below doc link,
http://docs.kony.com/konylibrary/visualizer/visualizer_user_guide/Default.htm#Custom_GCM.htm#Modifyin
You need to modify the notify_push_msg_clear value in pushconfig.xml file. Change the value to false to dismiss the notification.
We are using firebase push notification in Android and in iOS. The push is sent using FCM REST API call. Push type is notification with extra data node.
Here is a sample payload:
{
"notification" : {
"title": "title text",
"body": "message body text",
"sound": "default"
},
"data": {
"messageType": "xxx"
},
"to": "yyy",
"priority": "high",
"time_to_live": 0
}
This type of push notification does not show a heads up display when the app is in background and phone is on. -- Notification just are added to notifications bar but are not sneak peaked to user at the top of the screen. -- no matter if the current app is full screen app or not.
One solution that I have tried and is working is to shift to pure data message where we will not send any notification node, but just the data node and write the code to show notification ourselves and set notification priority to Max (ie .setPriority(Notification.PRIORITY_MAX)) on notification builder object.
But this seems to have issues on iOS where data only pushes are not received/shown to user if the app killed by user.
So is there any workaround to this? any solution that works on Android, but also does not break iOS.
You should set the NotificationPriority to PRIORITY_HIGH or PRIORITY_MAX for Android to show the notification. See Android Notification and Notification Priority for more details.
You should set these values using the constants, not using the strings. E.g.
{
token,
android: {
notification:
{
title,
body,
// See https://developer.android.com/reference/android/app/Notification#PRIORITY_MAX.
// This is deprecated in Android API level 26, but works for older versions.
notification_priority: 2,
// Always allow Android users to see the message in its entirety.
// See https://developer.android.com/reference/android/app/Notification#VISIBILITY_PUBLIC
visibility: 1
}
}
}
I am successfully able to send push notifications using IONIC Framework. But these notifications doesn't looks like I receive other android notifications, rather it these looks like normal Javascript alert.
Is there any setting to set push notification type like (alert or something else) ?
I go through the following link : https://devdactic.com/ionic-push-notifications-guide/
If someone has faced and resolved this, then please comment.
First screenshot shows push notification as Javascript alert.
Second screenshot shows default Android notification after locking phone's screen.
Third screenshot shows default Android notification after unlocking screen
I solved this problem by applying below code to $ionicPlatform.ready in my app.js file which shows notifications with onNotification event, if onNotification is not present then IONIC show default Javascript alert.
var push = new Ionic.Push({
onNotification: function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
pluginConfig: {
ios: {
alert: true,
badge: true,
sound: true
},
android: {
sound: true,
vibrate: true,
forceShow: true,
iconColor: "#601dc2"
},
}
});
While working with push notification you have Two possibilities to get notification One in the notification tray on the head of screen while your app is in background mode and Second when you are working with your app in foreground mode
First one is display like other notifications to notify that you got a notification for your app with message and logo whatever you set
But for other notification it is just use to get the data and message whatever you passed through it, and now its on you that how you want to show it in the application
Either you can set a div and hide show it when notification display with the design and position as you like or as per your app theme
<script>
function devicePushNotification(data)
{
if (data.additionalData.foreground == true)
{
$("#setNotificationText").text(data.message);
$("#setNotificationText").css("display","block");
}
}
</script>
<div style="width:50%;margin: 0 auto;display:none" id="setNotificationText">
</div>
Or you can just alert the message that you got a notification for anything you have passed like,
<script>
function devicePushNotification(data)
{
if (data.additionalData.foreground == true)
{
alert(data.message);
}
}
</script>
So, if you get the notification successfully, then you just have to create any well formed container to display it.
Hope this helps you
If the notification is clicked the application will be opened only if it is was not on the background and if the app is on the background it will not be brought to foreground. Android platform.
So I spent a lot of time finding the bug changing parameters and it turned out that<preference name="AndroidLaunchMode" value="singleInstance"/> parameter at config.xml was causing the problem. We used this parameter because deep links were creating new instances of the app. But for now we will ignore that problem.
Had the same issue but from other reason. The app was not opened when the notification was clicked.
The problem was that I changed the plugin from cordova-plugin-fcm to cordova-plugin-firebase
And the server that send the notification set the click_action to FCM_PLUGIN_ACTIVITY
So I changed (php):
$n = new Notification($title, $body);
return $n->setClickAction("FCM_PLUGIN_ACTIVITY")->setIcon('fcm_push_icon')->setSound('default');
To:
return $n->setIcon('fcm_push_icon')->setSound('default');
add this line in confix.xml
<preference name="AndroidLaunchMode" value="singleTop" />
and build app, works fine for me...
<preference name="AndroidLaunchMode" value="singleTop" />
When you add this line in config.xml even then two cases can happen or these cases might also be happening without adding this line
you won't be able to receive notification when app is in background or killed
if you received background notification even then when you click on
it. It won't open the respective application
So to solve first point, you should send the notification key whose value is object in object of fcm from backend service
So to solve second point, "click_action" key should not be passed in notification object
So your overall FCM object which is passed in fcm api should look like
{
"notification": {
"title": "Test Title",
"body": "message",
"sound": "default",
"icon": "fcm_push_icon",
"image": ""
},
"data": {
"action": "TEST"
},
"to":"caRvu_MeTN6HbMZKHfOO7y:APA91bEOEOAhpZNrDcDWew0uXM1HfKavyXbf3q4U090AHW5FmD7kDDxs4BRquaM*******************************************",
"priority": "high"
}
NOTE: This thing is only tested for Capacitor Fcm Plugin
Hope this will help you or somebody else :-)
Thanks!
I'm using Cordova 3.5.0-0.2.6 to cerate an Android application and using PushPlugin 2.2.1 to push notifications.
Everything works fine and get the notifications in my droid notifications bar when the app is in background, but when it's in foreground nothing happens when it get the notification. Wanted to make it play a sound or even show a popup alert to let the user know he has a new notification. Copied the example code from the plugin's github page (https://github.com/phonegap-build/PushPlugin) but it isn't working. The corresponding part of the code is this:
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (e.foreground)
{
// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
// playing a sound also requires the org.apache.cordova.media plugin
var my_media = new Media("/android_asset/www/"+ soundfile);
my_media.play();
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
window.location = 'iframe.html?url=' + e.payload.url;
if (e.coldstart) {
//$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
} else{
//$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
}
Not sure where the beep.wav file should be placed, I placed it into the www folder, but I'm 100% sure that's the place to put it.
Any one had this problem before? Any idea what I might be missing here?
Thanks,
Luciano
For android please add property "forceShow": "true" and it should work..
example code is below:
var push = PushNotification.init({
"android": {
"senderID": "xxxxxxxxx",
"forceShow": "true",
"icon": "icon",
"sound": true,
"vibration": true,
"badge": true
},
"browser": {
},
"ios": {
"senderID": "xxxxxxxxx",
"icon": "icon",
"gcmSandbox": true,
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});
but when it's in foreground nothing happens when it get the notification
This is the default behavior of PushPlugin. It creates a notification and the associated sound only when the application is in the background or closed.
Wanted to make it play a sound or even show a popup alert to let the user know he has a new notification.
The easiest solution would be to use Cordova Plugin Dialogs. All you would have to do is:
switch( e.event )
{
case 'message':
if (e.foreground) {
navigator.notification.beep(1);
}
.
.
}
Note that this beep will be the message tone configured by the user on his/her device.
Not sure where the beep.wav file should be placed, I placed it into the www folder
Not sure either, but I think it is the www directory too.
See also: Android won't play push sound while app not running