Search code examples
androidamazon-web-serviceslambdamessagingserverless

Using push notifications to trigger code within Android app?


Using a serverless architecture built on AWS, I'm looking for the best way to have users receive near-instant notifications of new "chats" within my Android app. I don't necessarily want to see a push notification appear in the phone's notification tray - I just want the app to listen for new messages, and update the view accordingly.

Here's my thinking: every time a user sends a chat, I'd basically trigger a Lambda function which would call SNS or IoT to publish the notification to any subscribed users of this chat.

But since SNS / IoT both work by sending "push notifications" to the phone, does that mean the message would have to appear within the phone's notification tray? I'm just looking for a way for my app to silently receive near-instant notifications from AWS and execute code to update its view.

Some other notes:

1) I don't want to build this using a server / EC2 with websocket listeners - I'd rather go serverless.

2) I've looked in Google's Firebase real-time DB which looks very capable, but as the rest of my architecture is on AWS, I'd like to stay there if possible


Solution

  • If you are making app for Android only, you can make use of the data message in FCM from Firebase. You can handle the message in onMessageReceived no matter your apps is on Foreground or Background.

    Apart from that, firebase provide integration with most server side language. You should be able to send the message in your lambda function.