简体   繁体   中英

Enabling push notifications on Android using Worklight

I'm having some issues getting push notifications to work on Android. I have added a pushSender to the android section of the application-descriptor.xml with the key that was generated (I've removed our key values).

<android version="1.0.5">
    <worklightSettings include="true"/>
    <pushSender key="our key" senderId="our sender"/>
    <security>
        <encryptWebResources enabled="true"/>
        <testWebResourcesChecksum enabled="true" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
        <publicSigningKey>our key</publicSigningKey>
    </security>
</android>

Every time I start the app, I get the message "Failed registering for push notifications. The application will not be able to receive notifications.

I thought for a little while that it may be because I was testing on our internal network and it needed access to the outside world, but even when it could get to the world, I still received the message. I've tried adding the securityTest parameter to the android tag, but it did not make any difference.

In the authenticationconfig.xml file, I've added a mobile security test to the security tests section:

    <mobileSecurityTest name="PushApp-securityTest">
        <testDeviceId provisioningType="none"/>
        <testUser realm="PushAppRealm"/>
    </mobileSecurityTest>

I have the realm set up like this:

    <realm name="PushAppRealm" loginModule="PushAppLoginModule">
        <className>com.worklight.core.auth.ext.PersistentCookieAuthenticator</className>
    </realm>    

And the login module is like this:

    <loginModule name="PushAppLoginModule">
        <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
    </loginModule>  

I'm really lost as to why it is failing to register. We're running Worklight 5.0.6.2.

From the comments:

For this to work, do you have to use some sort of actual login (ie entering a user id/password)?

If you are using Event source-based notifications, then yes - a login is required.
You can read an explanation here: receive GCM push without WLClient::connect()

It sounds like for this particular need of yours, you could use either Broadcast or Tag-based notifications. You can read more about these types in this user documentation topic . The topic also provides example implementations to follow-up with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM