Search code examples
androidpush-notificationwonderpush

Is it possible to use just the WonderPush REST API to send Push notifications to Android devices without using their SDK?


I'm developing an Android Application for a client who is very concerned about users data privacy.

WonderPush Android SDK is open source, but I would like to make several testings without upgrading the App in Google Play.

So, is it possible to use just the WonderPush REST API to send push notifications to devices without using their SDK?


Solution

  • Everything that the SDK does can be done without it, though using the SDK will greatly simplify the developer's life. It is especially easy to mock the SDK as it is open source and available on GitHub, and the REST API is documented.

    You can also test your application in the simulator or on your own devices, there is no need to deploy the new version of your WonderPush-enabled application to experiment with it.

    Push notifications can either be sent using your dashboard or using the REST Management API. The SDK is in charge of registering the application for push notification reception, collecting users and registering them on WonderPush, and displaying the received push notifications to the user.


    1a. If your application is not registered to receive push notifications

    You will need to follow the following two guides:

    In your BroadcastReceiver, simply get the alert extra string field using intent.getExtras().getString("alert") then format and display a notification using the NotificationManager.

    1b. If your application is already push notifications ready

    Unlike iOS, the Android platform does not define any official fields in a push notification, which is just an arbitrary JSON object. When sending your push notification you are interested mainly in how the application will present it to the user. As there is no standard, every provider does a different thing.

    So you will want to make sure the push notification you send uses the format your application (including any SDK you might already be using) is ready to accept.

    WonderPush uses the alert field to store the message to be displayed in the notification center in the user's device. Any rich (alert dialog box, html, map, etc.) notification configuration won't work out-of-the-box without the WonderPush SDK, because there is no standard. If the alert field does not suit you, you'll need to fill the "Payload override" in the notification form. You can also use the Management REST API to easily push custom notifications on the fly.

    2. Import users in WonderPush

    In order to send push notifications to your users' devices, WonderPush must know about them. You hence need to import your users by creating an installation object for each of them. The installation identifies an instance of your app, installed on a user's device. The key part is to provide WonderPush with the registrationId, called push token in our lingo.

    curl -XPOST https://api.wonderpush.com/v1/authentication/accessToken \
        -d clientId=YOUR_APP_CLIENT_ID \
        -d devicePlatform=iOS \
        -d deviceId=FOOBAR
    
    curl -XPATCH https://api.wonderpush.com/v1/installation \
        -d accessToken=TOKEN_FROM_PREVIOUS_CALL \
        -d body='{"pushToken":{"data":{"DEVICE_PUSH_TOKEN"}}}'
    

    3. Send push notifications

    Push notifications can either be sent using your dashboard, or using the REST Management API as follows:

    curl -XPOST https://management-api.wonderpush.com/v1/deliveries \
        -d accessToken=SERVER_PRIVATE_ACCESS_TOKEN \
        -d applicationId=YOUR_APP_ID \
        -d targetSegmentIds=@ALL \
        -d notification='{"alert":{"text":"Hello, WonderPush!"}}'