-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||
import com.google.firebase.ktx.Firebase | ||||||||||
import com.google.firebase.messaging.FirebaseMessaging | ||||||||||
import com.google.firebase.messaging.ktx.messaging | ||||||||||
import com.google.firebase.quickstart.fcm.R | ||||||||||
import com.google.firebase.quickstart.fcm.databinding.ActivityMainBinding | ||||||||||
import com.google.firebase.quickstart.fcm.java.MainActivity | ||||||||||
|
||||||||||
class MainActivity : AppCompatActivity() { | ||||||||||
|
||||||||||
|
@@ -84,6 +88,32 @@ class MainActivity : AppCompatActivity() { | |||||||||
Toast.makeText(this, "See README for setup instructions", Toast.LENGTH_SHORT).show() | ||||||||||
} | ||||||||||
|
||||||||||
override fun onResume() { | ||||||||||
super.onResume() | ||||||||||
|
||||||||||
// [START send_reg_token] | ||||||||||
FirebaseMessaging.getInstance().token | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||
.addOnCompleteListener { task: Task<String> -> | ||||||||||
if (!task.isSuccessful) { | ||||||||||
Log.w( | ||||||||||
TAG, | ||||||||||
"Fetching FCM registration token failed", | ||||||||||
task.exception | ||||||||||
) | ||||||||||
return@addOnCompleteListener | ||||||||||
} | ||||||||||
val token = task.result | ||||||||||
val tokenMap: MutableMap<String, String?> = | ||||||||||
HashMap() | ||||||||||
tokenMap["fcm_token"] = token | ||||||||||
Comment on lines
+106
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified to:
Suggested change
|
||||||||||
|
||||||||||
// Send token to backend server | ||||||||||
val callable = FirebaseFunctions.getInstance().getHttpsCallable("updateToken") | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can demonstrate KTX here too:
Suggested change
|
||||||||||
callable.call(tokenMap).getResult() | ||||||||||
} | ||||||||||
// [END send_reg_token] | ||||||||||
} | ||||||||||
|
||||||||||
companion object { | ||||||||||
|
||||||||||
private const val TAG = "MainActivity" | ||||||||||
|
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.