hansemannn / titanium-firebase-cloud-messaging

Use the Firebase Cloud Messaging SDK in Axway Titanium 🚀 Edit
Other
43 stars 31 forks source link

"force_show_in_foreground" not working #59

Closed DouglasHennrich closed 5 years ago

DouglasHennrich commented 5 years ago

This is my payload structure to send the notification with nodejs:

{"payload":{"apns":{"payload":{"aps":{"alert":{"title":"Usuário pedindo guincho","body":"Abra o app para verificar"}}}},"android":{"data":{"force_show_in_foreground":"true"},"restricted_package_name":"br.com.skappguincho","priority":"HIGH","ttl":5000,"notification":{"title":"Usuário pedindo guincho","body":"Abra o app para verificar"}}}}

I indeed receive that flag on my app but it doesn't display the notification alert.

{"type":"didReceiveMessage","source":{"fcmToken":"emPMoJjEM4w:APA91bFGQ8VjL-OoUjKA8ol4maDGc7k_ehlHbcdt6Fc_1rc5mDE0mQhSP2Dr16kYnkcf6f97MPd-xrvqei4dlP5ft-8NJRG-Za0nYaA6x5wwftg2mKOLuKJVtyCyBP7WNtsGdMxc3r7z","lastData":{},"apiName":"Ti.Module","bubbleParent":true,"invocationAPIs":[],"_events":{"didRefreshRegistrationToken":{},"didReceiveMessage":{}}},"message":{"messageType":null,"title":"Usuário pedindo guincho","data":{"force_show_in_foreground":"true"},"to":null,"body":"Abra o app para verificar","sendTime":1551799625053,"from":"820353491234","messageId":"0:1551799625059099%a22bf179a22bf179","ttl":5},"bubbles":false,"cancelBubble":false}

I'm using 1.4.0 TiSDK 7.5.1.GA

m1ga commented 5 years ago

will be fixed in https://github.com/hansemannn/titanium-firebase-cloud-messaging/pull/57/files#diff-5e74cf372f064c16492eddc1e4b32bb0L130 a link to a test version is in the ticket https://github.com/hansemannn/titanium-firebase-cloud-messaging/pull/57#issue-257539901

DouglasHennrich commented 5 years ago

Test it and still not working =/

m1ga commented 5 years ago

can you send a data message? so this payload:

{
    "payload": {
        "apns": {
            "payload": {
                "aps": {
                    "alert": {
                        "title": "Usuário pedindo guincho",
                        "body": "Abra o app para verificar"
                    }
                }
            }
        },
        "android": {
            "data": {
                "force_show_in_foreground": "true",
                "title": "Usuário pedindo guincho",
                "message": "Abra o app para verificar"
            },
            "restricted_package_name": "br.com.skappguincho",
            "priority": "HIGH",
            "ttl": 5000
        }
    }
}
DouglasHennrich commented 5 years ago

Now i'm receiving the notification but not that alert that popsup from device's top, but I get the notification sound and icon on Notification's tray

DouglasHennrich commented 5 years ago

My mistake... it's showing the alert but the custom sound isn't displaying

m1ga commented 5 years ago

default or custom sound? I don't specify anything special besides:

OS_ANDROID && fcm.createNotificationChannel({
    sound: 'default',
    channelId: 'default',
    channelName: 'General Notifications',
    importance: 'high' //will pop in from the top and make a sound
})

which shouldn't make any difference on my current device since it is an Android 7 phone. But your payload above (converted to php) work with sound, notification light and vibration in fore-/background

DouglasHennrich commented 5 years ago

I mean a custom sound, it's displaying the default one:

android: {
        data: {
            force_show_in_foreground: 'true',
            title: 'Usuário pedindo guincho',
            message: 'Abra o app para verificar',
            channel_id: `${process.env.FCM_CHANNEL_ID}`,
            sound: 'riderequest',
        },
        restricted_package_name: process.env.FCM_PACKAGENAME,
        priority: 'HIGH',
        ttl: 5000,
        // notification: {
        //  title: 'Usuário pedindo guincho',
        //  body: 'Abra o app para verificar',
        //  channel_id: process.env.FCM_CHANNEL_ID,
        //  sound: 'riderequest',
        // },
    },

on my app:

Alloy.Firebase.FCM.createNotificationChannel({
            sound: 'riderequest',
            channelId: 'SkappGuicho',
            channelName: 'SkappGuicho Notifications',
            importance: 'high', // will pop in from the top and make a sound
        })
captura de tela 2019-03-05 as 13 30 02
m1ga commented 5 years ago

does this version work? [removed link] The NotificationCompat.Builder always used the default sound and was ignoring a custom value (only the channel was using it). Can't test it currently :)

edit: already found a mistake...will upload a new file

hansemannn commented 5 years ago

Just released in android-1.5.0, thanks to our open source collaborators!

ricardoroth commented 5 years ago

I am using firebase.core 4.0 and firebase.cloudmessaging 2.0 but force_show_in_foreground is not working as expected. The app does trigger didReceiveMessage but android is not displaying the notification. I have tried all the following:

When the app is in background the notification is shown as expected. Thanks for your help

m1ga commented 5 years ago

@ricardoroth are you sending a data message? Please show your push payload

ricardoroth commented 5 years ago

Sure, this is the payload:

{"registration_ids":["f1L5YEhVnZs:APA91bHy5niJg...."], "notification":{"body":"This is a test notification #45","title":"sample title","android_channel_id":"my_channel","timestamp":"2019-04-04 9:44:16"}, "data":{"link":"www.google.com","force_show_in_foreground":true}}

m1ga commented 5 years ago

Send a proper data message (with title + message), then it will show the notification with force_show_in_foreground

$fields = array(
        'to' => "eNBB....",
        'data' => array(
            "link" => "value1",
            "title" => "title",
            "message" => "message",
            "force_show_in_foreground"=> "true",
        )
);
ricardoroth commented 5 years ago

Thanks for follow up, I added those values but the notification is still not showing up in foreground. I used the following code to debug:

fcm.addEventListener('didReceiveMessage', function(e) {
        Ti.API.info(JSON.stringify(e.message.data));
}

This is the output of it when the payload is sent:

[INFO] : {"icon":"https://example.com/icon.jpg","link":"somelink","force_show_in_foreground":"true","title":"some title","message":"This is a test notification #891"}

I also get: [ERROR] : NotificationManager: notifyAsUser: tag=null, id=2, user=UserHandle{0}

But this error also appears if the app is in background, and the notification is shown correctly so I don´t know how relevant that is. The difference in background is the tag value, like this:

[ERROR] : NotificationManager: notifyAsUser: tag=FCM-Notification:224068678, id=0, user=UserHandle{0}

(notification still shows up in background)

m1ga commented 5 years ago

are you sure you are sending a data notification? You have to remove the notification part

ricardoroth commented 5 years ago

I am sure I am sending a data notification. As you can see, e.message.data contains the expected fields, but the notification is not shown if the app is in foreground. I tried removing the notification part and that doesn´t change the behavior. The difference is only that it doesn´t work in background either if I remove that part. This wouldn't even be a solution cause I need the app to show the notifications in both modes.

I just noticed this error the first time a notification is sent with the app in foreground:

FirebaseMsgService: drawable.notificationicon not found; make sure it's in platform/android/res/drawable

Would this be a reason for the notification not showing up? I tried adding that icon to all my drawable folders but I still get that error. What am I doing wrong?

m1ga commented 5 years ago

@ricardoroth I recommend creating a different issue since you are hijacking this ticket :smile:

This wouldn't even be a solution cause I need the app to show the notifications in both modes. Not possible: https://firebase.google.com/docs/cloud-messaging/android/receive a Notification Message only triggers onMessageReceived so you have to create a local notification inside your app or patch this module to do it for you. Then - as mentioned before - you need to put in a title in the data part in order to send a proper data message. Otherwise the force_show_in_foreground will be ignored and it is a notification message.

Did you set the notificationicon part inside your tiapp.xml? This is only needed if you want to have a custom icon and then you have to put the icon there (see the part in the readme)

ricardoroth commented 5 years ago

@m1ga thanks for your help. I just solved this issue. I was sending channel_id instead of channelId in the payload. I see @DouglasHennrich was doing the same and this is probably why he was getting the behavior of the default channel. The background notification is always shown, even if a channelId is not sent.

It is now working in foreground and background now, but the behaviors of both are not equivalent as the intent of the foreground notification seems to be only to open the app, instead of opening it and calling didReceiveMessage. I will open a separate issue for that.