phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

Background notifications not working on Oreo #2729

Open arcm1138 opened 5 years ago

arcm1138 commented 5 years ago

Expected Behaviour

Display notification on lockscreen and tray

Actual Behaviour

Foreground working only (started when targeting SDK 26)

Plugin version

2.1.0

Sample Push Data Payload

php

$msg = array ( 'message' => "$message", 'title' => $title, 'vibrate' => 1, "android_channel_id" => "PushPluginChannel", 'priority' => "high", 'color' => "#222222", 'ledColor' => "[255, 255, 255, 255]", 'notId'=> "$time", 'sound' => "default" );

$fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg ); $headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch );

config.xml.. `

`

I am using Android Studio to publish.. have verified all SDK tools are present. Is there something I need to change in index.js?

Demokumar commented 5 years ago

I also have same issue

CSobol commented 5 years ago

Yet another issue that would be resolved if the maintainers of this repo would accept #2369 .

As of yet, none of the mainainers have weighed in on whether they will properly implement Android notifications or keep insisting we use hacky solutions that shouldn't be needed.

The author of the fork in question is actively keeping the code up to date, so I recommend you switch to his fork until such a time as the folks in charge of this repo accept the PR.

arcm1138 commented 5 years ago

Pretty ridiculous. And yes, "hacky" to say the least.

I finally got it working. I basically rebuilt the cordova project over and over until notifications were showing up on the lock screen/tray. Confirmed working on Android 9 as well.

2.1.2 + the FCM version (11.0.1) in config.xml did the trick.

cordova-support-google-services is NOT required.

My JSON payload did NOT have to change at all (as far as notification channels or anything else) regardless of what the current documentation is stating.

pabloleone commented 5 years ago

This PR solves the issues https://github.com/phonegap/phonegap-plugin-push/pull/2369