havesource / cordova-plugin-push

Register and receive push notifications
MIT License
150 stars 283 forks source link

Push received only in background #156

Open manuweb opened 2 years ago

manuweb commented 2 years ago

Bug Report

Error on Android When the app is in front, the push is not received and the push.on ('notification' ... is not executed. The push is recived in background and when de app is closed. If I tap on push the app came on front but not do anything.

When I send the push with $fields = array( 'registration_ids' => $registatoin_ids, 'data' => $data ); The push does not arrive, but i i change: $fields = array( 'registration_ids' => $registatoin_ids, 'notification' => $data ); The push arrive but not in front.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Cordova Packages:

cli: 11.0.0
    common: 4.0.2
    create: 4.0.0
    lib: 11.0.0
        common: 4.0.2
        fetch: 3.0.1
        serve: 4.0.0

Project Installed Platforms:

android: 10.1.1

Project Installed Plugins:

@havesource/cordova-plugin-push: 3.0.0
cordova-plugin-badge: 0.8.8
cordova-plugin-device: 2.0.3
cordova-plugin-geolocation: 4.1.0
cordova-plugin-inappbrowser: 5.0.0
cordova-plugin-screen-orientation: 3.0.2
cordova-plugin-splashscreen: 6.0.0
cordova-plugin-statusbar: 3.0.0
es6-promise-plugin: 4.2.2

Environment:

OS: macOS Monterey 12.1 (21C52) (darwin 21.2.0) x64
Node: v12.19.0
npm: 8.3.0

Sample Push Data Payload

$mensaje = array(
    'body'     => $message, //mensaje a enviar
    'message'     => $message, //mensaje a enviar
    'title'      => $title,// Titulo de la notificación
    'msgcnt'    => '1',
    'icon'=> 'icono',
    'key' => $valor,
    'timeToLive' => 3000,
);

Tested with this plugin and with phonegap-plugin-push and the same error

esstein commented 2 years ago

I added the forceMainActivityReload(false) after log "Don't Want Main Activity" on PushHandlerActivity.kt and app opens even when it is closed when I click on notification.

manuweb commented 2 years ago

forceMainActivityReload

I added the forceMainActivityReload(false) after log "Don't Want Main Activity" on PushHandlerActivity.kt and app opens even when it is closed when I click on notification.

I've done what you say and it still doesn't work.

The push only comes when the app is closed or in the background. If I click on the push it opens the app or brings it to the front but does not execute the push.on ('notification', function (data) {...

What do you use to send the push notification or data?

If I use notification in the payload the push arrives but with data it does not arrive.

This is my payload:

$fields=array(
            "registration_ids" =>$registatoin_ids,
            "notification" =>array (
                'body'     => $notification['body'], //mensaje a enviar
                'message'     => $notification['message'], //mensaje a enviar
                'title'      => $notification['title'],// Titulo de la notificación
                'msgcnt'    =>$notification['msgcnt'] ,
                'icon'=> $notification['icon'],
                'image'=> $notification['image'],
                'key' => $notification['key'],
                'timeToLive' => $notification['timeToLive']
 ); 

Thanks.

manuweb commented 2 years ago

I got it with Android 9.0.0 (& Android Studio 4.1.2 ) and phonegap-plugin-push, with Android 10.x.x still do not work.

esstein commented 2 years ago

I have to move PushNotification.init on "setTimeout(()=>{},2500)". If push payload has "icon", the icon image must be in "res" of app, or app crashes when the notification arrives. When app crashes because of notification icon, the notification doesn't show and you think that it has not arrived. I have to figure out this in logcat to see the exception message.

robvandijk commented 2 years ago

I added the forceMainActivityReload(false) after log "Don't Want Main Activity" on PushHandlerActivity.kt and app opens even when it is closed when I click on notification.

I can confirm this works for me as well (tested on Android 9 and 11).