-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
FirebaseMessaging.getInstance().token | |
Firebase.messaging.token |
val tokenMap: MutableMap<String, String?> = | ||
HashMap() | ||
tokenMap["fcm_token"] = token |
There was a problem hiding this comment.
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:
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") |
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this comment.
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.
import com.google.firebase.functions.FirebaseFunctions | |
import com.google.firebase.functions.FirebaseFunctions | |
import com.google.firebase.functions.ktx.functions |
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.