Android and Linux

Sunday, July 10, 2011

Prowl-like custom Android push notifications

Oh boy, I've been wanting this forever. When I used the iphone a year and a half ago, there was an app called Prowl which allowed you to send any push notification to your phone. You could, for example, have your computer send a notification when it booted and the notifications could say anything up to a 1024 character limit.

I've really wanted that for Android and hoped to see it when Google came out with the Cloud to Device Messaging service but I didn't find it until now.

Notify My Android will allow you to send custom push notifications to your phone and here's how to use it from the Linux command line.

You first get the app from the Market then create an account on their website. Once you log in to the website, go to "my account" and generate an API key. Now it's as simple as crafting a cURL or wget command to post the data.

curl -k https://nma.usk.bz/publicapi/notify -F apikey="YOURKEY" -F application="Testing" -F event="test event" -F description="hello world"

wget -q -O - --post-data "apikey=YOURKEY&application=APPNAME&event=EVENT&description=this is the description area where the actual notification text is supposed to go" https://nma.usk.bz/publicapi/notify

The fields can be found on the website on the API page. cURL is easier to understand here because you just put a -F then the name of the field to post to and the text to post. -F apikey="YOURKEY" is pretty easy to decipher, but wget is actually doing the same thing, just differently.

One trick I always thought was useful was to set it up so you can pipe output to the phone. You can pipe output to this short script and it will show up on your phone. I include both wget and cURL. cURL is simpler to use on a computer but wget can be used on your phone, however, I've found that wgen on the phone doesn't allow secute https. You can still use regular unsecure http if you think the threat is low enough.

#! /bin/sh
out=$(< /dev/stdin)
wget -q -O - --post-data "apikey=YOURKEY&application=APPNAME&event=EVENT&description=${out}" https://nma.usk.bz/publicapi/notify

#! /bin/sh
out=$(< /dev/stdin)
curl -k https://nma.usk.bz/publicapi/notify -F apikey="YOURKEY" -F application="Testing" -F event="test event" -F description="${out}"

Followers