Żabojad
Żabojad

Reputation: 3095

Can't get pushwoosh to receive notifs on Cordova Android

For some reason I do not understand, I do not receive PN on my Android device.

I did configure GCM in console.firebase.google.com.

I did put the generated google-services.json file in the platform/android folder of my cordova project.

I of course installed the cordova pushwoosh-phonegap-plugin plugin.

I added and call this code at the bootstrap of my app:

function initPushwoosh(store) {
    var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");

    // Should be called before pushwoosh.onDeviceReady
    document.addEventListener('push-notification', function(event) {
        console.log('RECEIVED PN: ',event);
    });

    // Initialize Pushwoosh. This will trigger all pending push notifications on start.
    pushwoosh.onDeviceReady({
        appid: "...",
        projectid: "..."
    });

    if (myApp.pnToken == null) {
        pushwoosh.registerDevice(
            function(status) {
                var pushToken = status.pushToken;
                console.log('received token',pushToken);
            },
            function(status) {
                console.error(status);
            }
        );
    }
    else {
        pushwoosh.getPushwooshHWID(function(pwid){console.log('PUSHWOOSH ID: ',pwid);});
    }
}

At runtime, I see that my app successfully subscribe to PUSHWOOSH (I receive a pw token and have a pw client id) and I see my unique test Android device in the Android "subscribers" count in the Pushwoosh admin interface.

However, the "push-notification" event is never triggered when I send a sample notif from the PW admin interface...

Here are some more info with a portion of the logcats:

    01-17 11:26:57.144 9254-9653/my.app D/Pushwoosh: [CordovaPlugin] Plugin Method Called: onDeviceReady
    01-17 11:26:57.145 9254-9653/my.app I/Pushwoosh: [NotificationManager] App ID: XXXXX-XXXXX
    01-17 11:26:57.147 9254-9653/my.app I/Pushwoosh: [NotificationManager] Sender ID: XXXXXXXXXX
    01-17 11:26:57.149 9254-9254/my.app D/Pushwoosh: onAppReady
        sendAppOpenEndTagMigrate
    01-17 11:26:57.154 9254-9653/my.app D/Pushwoosh: [CordovaPlugin] Plugin Method Called: getPushwooshHWID
    01-17 11:26:57.160 9254-9254/my.app D/Pushwoosh: [[BusinessCase]] trigger welcome-inapp
        [BusinessCase] welcome-inapp condition not satisfied
        [[BusinessCase]] trigger app-update-message
    01-17 11:26:57.161 9254-9254/my.app D/Pushwoosh: [BusinessCase] app-update-message condition not satisfied
    01-17 11:26:57.172 9254-9254/my.app D/Pushwoosh: [JobServiceEngineImpl] onStartJob: android.app.job.JobParameters@344323
    01-17 11:26:57.183 9254-18165/my.app D/Pushwoosh: [RequestManager] Try To send: applicationOpen; baseUrl: https://DB224-ABAD6.api.pushwoosh.com/json/1.3/

    01-17 11:26:57.588 9254-18165/my.app I/Pushwoosh: [RequestManager] 
        x
        |     Pushwoosh request:
        | Url: https://xxxxx.api.pushwoosh.com/json/1.3/applicationOpen
        | Payload: {"request":{"application":"XXXXXX","hwid":"xxxxxx","v":"5.11.0","device_type":3,"userId":"xxxxx","device_name":"Phone","language":"fr","timezone":3600,"android_package":"my.app","jailbroken":1,"device_model":"Samsung SM-G950F","os_version":"8.0.0","app_version":"1.3.4","notificationTypes":6}}
        | Response: {"status_code":200,"status_message":"OK","response":{"required_inapps":[]}}
        x

What could be wrong?

Few questions: - Is platform/android the right place for the google-services.json file ? - Other question: is any of those steps needed with the cordova plugin? - The last step (optional apparently) of the Firebase SDK configuration doesn't end:

enter image description here

Could that have any consequence?

Upvotes: 1

Views: 381

Answers (1)

Żabojad
Żabojad

Reputation: 3095

OK, I had 2 issues: First I was using the "old" type of FCM Server Key while I should have used the new one. Second, I was expecting to receive the push notif while app is in foreground by listening to the 'push-notification' event. I should have listened to the 'receive-push' event instead... Doing so solved the troubles I was having with actually receiving the notifications (and their precious userdata in my js code).

Upvotes: 0

Related Questions