I wanted to send alert messages from my Python application to a few Android devices when certain event triggered. The requirement is time sensitive: preferbly notification is received within 5 minutes. I doubt Firebase Cloud Messaging
is fast enough, SMS
is probably too costly, thus I wanted to give Pushy
a spin since it is marketed as Lightning-fast, highly-reliable push notification delivery
.
NOTE: Other options to experiement include WhatsApp Business API or Telegram API.
Notes about Pushy
- Pushy is free for up to 100 devices, which is perfect for my case since I only have a few.
- I though I could send message to Pushy Demo App on Google Play, but it seems I can't since I need to register the
Android Package Name
(me.pushy.example
cannot be used since it is registered by another user). Source code of Pushy Demo is available so I can change the Package ID and compile another version. - How can I send notifications to devices in Doze mode?: need to handle the Doze Mode on Android 6+ devices
- Why are my notifications being delayed when my app is in the background?: seems like each brands of devices has their custom implementation to handle power hungry app, thus making push notification unreliable.
def send_alert(to, message): PUSHY_SECRET_API_KEY = 'e56b....' params = { 'to': to, 'data': { 'message': message } } url = f"https://api.pushy.me/push?api_key={PUSHY_SECRET_API_KEY}" r = requests.post(url, json=params) if r.status_code == 200: # print(json.dumps(r.json(), indent=2)) data = r.json() print(json.dumps(data, indent=2)) else: print(r.json()['error']) r.raise_for_status()
Usage
PUSHY_DEVICE_TOKEN = '6b35...'send_alert(to=PUSHY_DEVICE_TOKEN, message='Hello')