Skip to content

Android Notifications

Sharina Stubbs edited this page Nov 8, 2019 · 5 revisions

A push notification that shows up on the pulldown "tray" on the phone. Text notifications are not push notifications. The user has to have opted into receiving those push notifications when they either download the app or later when they adjust their push notifications.

AWS Framework that allows notifications

The Framework is called Pinpoint.

You are able to send notifications on the AWS dashboard and appear on phone. Pinpoint > All projects > project... Go to Campaigns. No code is involved to send a notification.

  • A deep link is a specific activity in the app
  • media urls set allows you to set the image set in the notification. Must choose a nice png - square with a background that is transparent.
    • Can put url into Android icon or Android small icon, for example

Worry about:

  • If I want to notify a user about something, and they are logged into a ton of devices, do you notify all of those devices?
  • What counts as reading a notification
  • What data do you get after the notification?

The way you are able to send push notifications: Code runs on an app You want to trigger a push notification when something happens in the cloud, not necessarily when something happens on the app.

At least 3 things needed to allow push notifications:

  • The user's phone
  • Google
  • AWS
  • Your stuff - your server / dynamo stuff / lambdas

Steps in the process

  1. Phone to Google: "Hello, give me your Device Token"
  2. Google gives a device token
  3. App registers with AWS - "register me! My token is ____"
  4. AWS and Poinpoint stores that device token associated with the logged in user (integrates with Cognito)
  5. Someday in the future... a marketing person logs into the AWS pinpoint console, or you use a lambda function or something, and from where-ever, you talk to AWS, and you say, "send notification (text and who the notification goes to).
  6. AWS makes a request to Google - "hey, send notifications to these device tokens"
  7. Google uses that device token to reach back to the phone and say, "hey, show this push notification"
  8. The phone's app will run code that has been listening for a push notification.

The code

It's not too large...

For a demo from Code401-Java-d6, see Front Row on Thurs, November 7, 2019 from 4pmish, give or take.

Pinpoint

  • A Simple Notification Service

The Code:

In the terminal:

amplify add notifications
  • You must use FCM - firebase cloud messaging - to send push notifications to an Android phone.

Firebase makes it so you only need the following thing, instead of a fancy passwordy thing: https//console.firebase.google.com. This opens up a console of firebase projects I've done.

grab API key

In firebase, go to the gear > project settings, go to cloud messaging, which has a server key. Copy the key, and copy into the CLI

Add firebase to project

Go back to firebase. Hit the android icon in create an app, or something. Follow instructions

Go to aws android doc for push notifications

Go to Push Notifications

Test messages

Don't worry about them on AWS. They aren't working yet.

Also, go to console.firebase.google.com/project/--- project name ---:

  • Can write a test message here.

HINT: If I want to build another android app for fun:

Can totally use Firebase instead of AWS, because it's soooo easy to use. They are great for little apps - their free tier is always free. However, when you upgrade, they are somewhat more expensive than AWS.

  • Cloud FireStore
  • CLoud functions
  • Analytics
  • Everything amplify can do

Resources

Clone this wiki locally