Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Demo always sending token to server #1353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kroikie
Copy link
Contributor

@kroikie kroikie commented Feb 17, 2022

Developers should regularly send their FCM registration token to their corresponding server. This way the server can determine the freshness or staleness of a particular token and decide whether or not to send messages to that token.

This snippet demonstrates sending the FCM registration token to a callable function that will store it appropriately.

@kroikie kroikie changed the title Demo always sending token to server [WIP] Demo always sending token to server Feb 17, 2022
Copy link
Contributor

@marinacoelho marinacoelho left a comment

Choose a reason for hiding this comment

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

It looks good to me!

super.onResume()

// [START send_reg_token]
FirebaseMessaging.getInstance().token
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a Kotlin snippet, we might want to demonstrate KTX here

Suggested change
FirebaseMessaging.getInstance().token
Firebase.messaging.token

Comment on lines +106 to +108
val tokenMap: MutableMap<String, String?> =
HashMap()
tokenMap["fcm_token"] = token
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified to:

Suggested change
val tokenMap: MutableMap<String, String?> =
HashMap()
tokenMap["fcm_token"] = token
val tokenMap: MutableMap<String, String?> = hashMapOf("fcm_token" to token)

tokenMap["fcm_token"] = token

// Send token to backend server
val callable = FirebaseFunctions.getInstance().getHttpsCallable("updateToken")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can demonstrate KTX here too:

Suggested change
val callable = FirebaseFunctions.getInstance().getHttpsCallable("updateToken")
val callable = Firebase.functions.getHttpsCallable("updateToken")

@@ -8,10 +8,14 @@ import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import com.google.firebase.functions.FirebaseFunctions
Copy link
Member

@thatfiredev thatfiredev Feb 25, 2022

Choose a reason for hiding this comment

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

If the comment above gets applied, we'll need to import functions ktx.

Suggested change
import com.google.firebase.functions.FirebaseFunctions
import com.google.firebase.functions.FirebaseFunctions
import com.google.firebase.functions.ktx.functions

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.

5 participants