Ad

Adobe Phonegap Push Notifications With Firebase Cloud On Android

Since 2018 the standard Phonegap push notifiction sample project no longer works. I am struggling to find a functional way to send a push notification to an app. So far I have done the following:

  1. Set up the Adobe Phonegap push notification sample project
  2. Set up a Firebase Cloud account and created a project and added an Android app to it.
  3. Downloaded the google-services.json
  4. Installed phonegap-plugin-push (1.8.0 as apparently anything over 2.0 has problems), and included my Sender ID
  5. Installed cordova-android-support-gradle-release, cordova-android-play-services-gradle-release and cordova-android-firebase-gradle-release
  6. Amended the index.js so that the sender ID is no longer sent in the PushNotification.init Android object (apparently no longer required)
  7. Amended the index.js so that the pushServiceURL is included in the PushNotification.init Browser object (apparently this IS required for testing in the browser)
  8. Set up and published a push message campaign in Firebase cloud, to trigger when app is opened

I am using Android 8.1.0. I have installed the Adobe Phonegap Developer App

Result: I run Phonegap serve in the CLI. I see the following in my CLI:

Updating manifest.json with push properties…
[phonegap] starting app server...
[phonegap] listening on 192.168.1.57:3000
[phonegap]
[phonegap] ctrl-c to stop the server
[phonegap]
Updating manifest.json with push properties…
Manifest updated with push sender ID
Manifest updated with push sender ID
[phonegap] 200 /socket.io/?EIO=3&transport=polling&t=MbsZP-M
[phonegap] 200 /socket.io/? 
EIO=3&transport=polling&t=MbsZSMw&sid=Wyc9htsKdIkXHCtKAAAA
[phonegap] 200 /__api__/update
[phonegap] 200 /__api__/update
[phonegap] 200 /__api__/update
[phonegap] 200 /socket.io/socket.io.js

...everything looks good so far. I load up the Phonegap Developer App on my Android device and connect and I see:

[phonegap] [console.warn] Content Security Policy has been modified to be: 
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' gap: ws: https://ssl.gstatic.com;style-src 'self' 'unsafe-inline' data: blob:;media-src *;img-src * 'self' data: content:;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">
[phonegap] [console.warn] Content Security Policy has been added: <meta http-equiv="Content-Security-Policy" content="default-src * gap: ws: https://ssl.gstatic.com;img-src * 'self' data: content:;style-src 'self' 'unsafe-inline' data: blob:;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">
[phonegap] 200 /__api__/appzip
[phonegap] 200 /socket.io/socket.io.js
[phonegap] 200 /socket.io/?EIO=3&transport=polling&t=MbsaRlk
[phonegap] 200 /socket.io/?EIO=3&transport=polling&t=MbsaRmS&sid=R8RzNxpm8Z-XkKNtAAAD
[phonegap] [console.log] Received Device Ready Event
[phonegap] [console.log] calling setup push
[phonegap] [console.log] calling push init
[phonegap] [console.log] after init
[phonegap] [console.log] Device Push ID:
[phonegap] dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQ-VTTagpGVnQvgqZUEUSlzKnAabrw4kz0W45RnrsbJNKAbFZbh
[phonegap] [console.log] registration event: dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQ-VTTagpGVnQvgqZUEUSlzKnAabrw4kz0W45RnrsbJNKAbFZbh

...again, everything looks good, and the message on the screen says "registered". so everything seems ok except no message is received. And no console log to inform me of any message attempt.

I have also tried to add test device using the Firebase instance ID. From my code I assume "dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQ-VTTagpGVnQvgqZUEUSlzKnAabrw4kz0W45RnrsbJNKAbFZbh" is the test device? So I add that but Firebase says it is an "invalid format". I then tried just the code before the colon ("dijoTzuKUVd") which Firebase accepted (but no idea if that is right) and tried to send the message again. But still nothing.

Does anybody know what I am missing?

ADDITIONAL to this, when I run the app in any browser I get the JS error:

Uncaught Error: Service Workers are not supported on your browser.
at new PushNotification (push.js:89)
at Object.init (push.js:366)
at Object.setupPush (index.js:42)
at Channel.onDeviceReady (index.js:38)
at Channel.fire (cordova.js:798)
at cordova.js:229

...so I can't test it on the browser either.

Any help appreciated.

Ad

Answer

Adobe Phonegap no longer supports notifications when testing through the local server.

I ended up using the phonegap-plugin-push library to receive push notifications from FCM.

https://github.com/phonegap/phonegap-plugin-push

Ad
source: stackoverflow.com
Ad