Monday, August 24, 2015

Android Notifications Without an App

What if you have a pile of Android devices and want to send some kind of notification to them? Android supports GCM - Google Could Messaging - but you must write an app to receive these messages. That's fine and works great, but what I wanted was the convenience of pushing messages to my devices, without the inconvenience of having to write a custom app, and keep that app running to receive the notifications.

The idea that I hit upon was to create a "dummy" Gmail account and send XMPP chat messages from the dummy account to my "real" Gmail account, which is connected to my Android devices. This results in a native notification popping up on all connected devices.

Unfortunately for us, Google has masked our Gmail accounts such that you cannot just send XMPP messages directly to your Gmail address. This mask is a unique 26-character string at the domain public.talk.google.com (shown in the green box below). The reason for the mask is to make it more difficult for people to spam you with chat messages. What is needed is a way to discover the masked address so we can send XMPP messages to it.


To discover the masked address, I created a Python script that logs into the dummy account. While that script is running, send a chat from your main account to the dummy account (using the Gmail web interface). The Python script will catch the message and dump the "from" address, which is exactly what we need.

Here is the Python script to do it. Make sure to follow the directions closely. You may also find that it works best on Linux.


Once you have the masked account, you can send your main Gmail account notifications using XMPP libraries in a variety of different languages. Shown above, I have been using this technique to send notifications for a home automation system.

No comments:

Post a Comment