Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push received only in background #156

Open
manuweb opened this issue Jan 10, 2022 · 5 comments
Open

Push received only in background #156

manuweb opened this issue Jan 10, 2022 · 5 comments

Comments

@manuweb
Copy link

manuweb commented Jan 10, 2022

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
Copy link

esstein commented Jan 12, 2022

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
Copy link
Author

manuweb commented Jan 13, 2022

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
Copy link
Author

manuweb commented Jan 17, 2022

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
Copy link

esstein commented Jan 18, 2022

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
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants