Search code examples
androidiospush-notificationphonegap

Phonegap Push Notifications for Android in 2019 - does it work?


I've seen a lot of tutorials and forum posts about using Push notifications with Phonegap, but most of these seem out of date. Does anybody know whether this works today (2019)?

I created the Push Notification demo through Phonegap and ran it on my Android 8 device. While it runs and says "Registered", there is no sample notification.

I tried sending a push via the CLI and that didn't work either (I have been told this was removed so will no longer work, despite Adobe's out of date tutorial page)

(note the Phonegap Developer app says it isnt compatible with Android 8 on the Play Store so had to download the APK from elsewhere. Was that a sign that nothing would work?)

Then I found that there was a "new" push service for Phonegap, which I also downloaded, only to find out that this is no longer in service either.

So NOW I find that there are some 3rd party apps which can provide push services (mostly not free). Services such as "PushWhoose".

Does anybody know, do these 3rd party services work? Which are the most reliable ones to use? And on what versions of Android and iOS do they work?

Any help appreciated.


Solution

  • I have many phonegap (CLI-8.0.0) applications in production that are currently receiving notifications in 2019 so yes it's work.

    I used the 3rd party Cloud messaging by Firebase (https://firebase.google.com/docs/cloud-messaging/) and the phonegap-plugin-push (version 2.1.3 for Android and last version for iOS)

    We have tested the following on Android 7 and 8 and iOS 12.

    Notifications were sent with the C# Firebase API.

    How to use Firebase with Phonegap :

    First you have to install 4 plugin for Android :

    <plugin name="phonegap-plugin-push" spec="2.1.3" />
    <plugin name="cordova-android-support-gradle-release" spec="https://github.com/dpa99c/cordova-android-support-gradle-release.git" />
    <plugin name="cordova-android-play-services-gradle-release" spec="https://github.com/dpa99c/cordova-android-play-services-gradle-release.git" />
    <plugin name="cordova-android-firebase-gradle-release" spec="https://github.com/dpa99c/cordova-android-firebase-gradle-release.git" />
    

    I used 2.1.3 version of plugin for android because the last version didn't work for me.

    *-gradle-release grants you full compatibility between phonegap-plugin-push and other plugins because there are often conflicts

    For iOS i used last version :

    <plugin name="phonegap-plugin-push" />
    

    After that, you have to register your apps to firebase until you have sender id and google-services.json.

    For apple you have to grant your certificate the push notification rights and get an APNS certificate.

    When you have your sender id, google-services.json and GoogleService-Info.plist you just have to configure your config.xml like this:

    <platform name="android" custom="push">
        <plugin name="cordova-android-support-gradle-release" spec="https://github.com/dpa99c/cordova-android-support-gradle-release.git" />
        <plugin name="phonegap-plugin-push" spec="2.1.3">
            <param name="SENDER_ID" value="XXXXXXXXXXXXXXXXXXXXXX" />
        </plugin>
        <plugin name="cordova-android-play-services-gradle-release" spec="https://github.com/dpa99c/cordova-android-play-services-gradle-release.git" />
        <plugin name="cordova-android-firebase-gradle-release" spec="https://github.com/dpa99c/cordova-android-firebase-gradle-release.git"/>
        <resource-file src="google-services.json" target="/app/google-services.json" />
    </platform>
    
    <platform name="ios" custom="push">
        <plugin name="phonegap-plugin-push">
            <param name="SENDER_ID" value="XXXXXXXXXXXXXXXX" />
        </plugin>
        <resource-file src="GoogleService-Info.plist" />
    </platform>
    

    google-services.json and GoogleService-Info.plist has to be at the same level of your config.xml in the www folder.

    After that, the documentation of the plugin will be able to help you better than me.