Skip to content

Firebase Push Messaging support#22

Open
dotbugfix wants to merge 2 commits intoAppNotificationfrom
FirebasePush
Open

Firebase Push Messaging support#22
dotbugfix wants to merge 2 commits intoAppNotificationfrom
FirebasePush

Conversation

@dotbugfix
Copy link
Member

New features

  • Registering app with Firebase
  • Getting a unique instance ID
  • Subscribing to a topic and receiving messages sent to it

Log messages from testing

Get Instance ID

2019-03-24 19:17:46.296 6434-6434/com.saraswitty.wittyapp I/c*.s*.w*.MainActivity: [Firebase] Instance ID token: f_wvn6infE0:APA91bHsYjCBx27WnU4fUnRkGomfkdSWameo0NTEadmKyx5APbEXcEEY8ZHUuAkLo6wGxAI_5Cl7IsSiOvn7hlMpJORaMNftWHmqVRAP8owufPHC82AXHUg7-09Xcb6YFWASwlzNMOXI

Receive direct message from Firebase Console

2019-03-24 19:18:04.410 6434-7184/com.saraswitty.wittyapp I/*rebaseMessagingService: [Firebase] Message From: 998868710353
2019-03-24 19:18:04.411 6434-7184/com.saraswitty.wittyapp I/*rebaseMessagingService: [Firebase] Message data payload: {}
2019-03-24 19:18:04.413 6434-7184/com.saraswitty.wittyapp I/*rebaseMessagingService: [Firebase] Message Notification Body: Just saying hi!

Receive message on subscribed topic

019-03-24 19:23:29.245 6434-8257/com.saraswitty.wittyapp I/*rebaseMessagingService: [Firebase] Message From: /topics/weather
2019-03-24 19:23:29.245 6434-8257/com.saraswitty.wittyapp I/*rebaseMessagingService: [Firebase] Message data payload: {customKey=customValue}
2019-03-24 19:23:29.248 6434-8257/com.saraswitty.wittyapp I/*rebaseMessagingService: [Firebase] Message Notification Body: Just saying hi!

Screenshots

Screenshot_20190324_192127
Screenshot_20190324_192200
Screenshot_20190324_192509
Screenshot_20190324-191842~2

@ajaynair
Copy link
Contributor

ajaynair commented Mar 25, 2019

Are notifications queued? What happens if the app is not immediately available for the notification from firebase?

@ajaynair
Copy link
Contributor

Are there any constraints on firebase usage (No.of. notifications we can send, No.of. notifications we can send at a time etc.)?

@ajaynair
Copy link
Contributor

What are the steps required to test your changes on my phone?

  1. Pull your code
  2. ?

val token = task.result?.token

// Log and toast
val msg = "[Firebase] Instance ID token: " + token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val token = task.result?.token

i.e. token can be null
Check if token is null here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok will do.

msg = "Failed to subscribe to topic 'weather'"
}
logger.info("[Firebase] Subscribe to topic 'weather': " + msg)
Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should use toast only for failure cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This was only for quick debugging.

@dotbugfix
Copy link
Member Author

Are notifications queued? What happens if the app is not immediately available for the notification from firebase?

Yes, see Lifetime of a message:

If the device is not connected to FCM, the message is stored until a connection is established (again respecting the collapse key rules). When a connection is established, FCM delivers all pending messages to the device. If the device never gets connected again (for instance, if it was factory reset), the message eventually times out and is discarded from FCM storage. The default timeout is four weeks, unless the time_to_live flag is set.

@dotbugfix
Copy link
Member Author

Are there any constraints on firebase usage (No.of. notifications we can send, No.of. notifications we can send at a time etc.)?

Stackoverflow says its unlimited.

@dotbugfix
Copy link
Member Author

What are the steps required to test your changes on my phone?

1. Pull your code

2. ?

On your laptop, open the Firebase Console and login as 'dotbugfix' (not your Google account). I've registered WittyApp as a project there. You can then follow the screenshots above to send a new notification and it should show up on your phone after the app is opened at least once (to subscribe to the topic).

Logcat on Android will print the unique instance ID for your phone - you can use that to send a 'test message' from Firebase. This is not required as we can send a message on the 'weather' topic instead of a particular device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants