One of the most powerful features of android platform is push notifications which you can keep your users informed about new features of your apps or show them some special offers. This service is called as “Amazon Device Messaging(ADM)” on Amazon side.
I assume you already have integrated ADM into your application and trying to test push notifications on your Amazon device. Ok, let’s see those push notifications. We have two “.sh” files which include curl commands for getting access token and sending push notification to your registered device.
Getting Access Token
Firstly you need an access token for sending push notification. Save the following codes as “adm_getAccessToken-test.sh”.
#CLIENT_ID & CLIENT_SECRET parameters are application specific!!!
#You can get from Amazon Developer Console :)!!!
CLIENT_ID=amzn1.application-oa2-client.a...3
CLIENT_SECRET=f69c219247459c141...d1589c88b888eed7b
curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: e902b849-6578-9c43-92b4-6c55f2e246e9" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&scope=messaging%3Apush&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET" https://api.amazon.com/auth/O2/token
Here we have two parameters as “CLIENT_ID” and “CLIENT_SECRET”. You can learn your application specific “CLIENT_SECRET” and “CLIENT_ID” from your Amazon Developer Console page.
After replacing these two parameters with your application and device information, you can run this “adm_getAccessToken-test.sh” or copy/paste it into your console. If everything goes well, you will obtain an access token in the result as follows.
{"access_token":"Atc|MQEBIM0Dc27MHx928R3chgdJg8M9QfoefieqnamEN_RZ72psemXLI0M_oFt2w_pXjCE5FFiLTrB2l9B6BU1JxNEXbqV9KV3mLp9RjPS8JID2-jT6XD76KQzP1mHvisQKwrkxrzTc1lV0zOtVkhC5xFVES0pu_aH6VU9Q7plfqR-JEKb0q...nRCzzpYpF2l-iHBnTNF0v4bPNwCTU3ywPGPZVzv0I","scope":"messaging:push","token_type":"bearer","expires_in":3600}
Sending Push Notification
After getting access token, you are ready to send push notification. Save the following codes as “adm_sendPush-test.sh”.
#ACCESS_TOKEN is obtained using adm_getAccessToken-test.sh
#REGISTER_ID is from adb logs.
ACCESS_TOKEN="Atc|MQEBIEshY-...76ouqKrndpvMw2YDHZ--oP6HIGgUgrLqGkI9wx0"
REGISTER_ID="amzn1.adm-registration.v2...M2b3c9PQ"
curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" -H "X-Amzn-Type-Version: com.amazon.device.messaging.ADMMessage@1.0" -H "Accept: application/json" -H "X-Amzn-Accept-Type: com.amazon.device.messaging.ADMSendResult@1.0" -H "Cache-Control: no-cache" -H "Postman-Token: c7be00c4-232c-251e-3091-8e846214c3cd" -d '{
"data":{"message":"Your message","title":"Amazon Push Message Title","tickerText":"Ticker ticker amazon"}
}' https://api.amazon.com/messaging/registrations/$REGISTER_ID/messages
You should obtain “REGISTER_ID” from adb logs after registering to ADM. Now you can run “adm_sendPush-test.sh” or copy/paste it into your console for sending push notification. If everything goes well, you will see a push notification on your amazon device.