Get fcm token when user is logged for the first time
There is a mistake in your code.
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (task.isSuccessful){
Log.w(TAG, "Fetching FCM registration token failed", task.exception)
return@addOnCompleteListener
}
}
task.isSuccessful
block should store the token but it was return and loging error ?.
Ref : https://firebase.google.com/docs/cloud-messaging/android/client#retrieve-the-current-registration-token
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w(TAG, "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
// Get new FCM registration token
val token = task.result
// Log and toast
val msg = getString(R.string.msg_token_fmt, token)
Log.d(TAG, msg)
Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
})
How to get Android Device Token in Kotlin for Firebase Cloud Messaging
FirebaseInstallations
isn't the correct token for FCM! I had to use FirebaseMessaging
and use the following:
FirebaseMessaging.getInstance().token
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w(TAG, "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
val token = task.result
Log.d(TAG, token)
})
How to get the device token in flutter
You have to create the FirebaseMessaging instance. Change to:
@override
void initState() {
FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance; // Change here
_firebaseMessaging.getToken().then((token){
print("token is $token");
});
}
Verify if fcm token belongs to an android or ios device
The following might help you to customize notification messages based on the platform:
https://firebase.google.com/docs/cloud-messaging/send-message#customize-messages-across-platforms
If you want to distinguish the tokens manually, then a possible hack would be to add the platform name as a prefix when storing tokens in a database from your frontend app. Then, you can filter out the tokens on your backend by implementing a programming logic i.e. creating separate arrays for android and IOS tokens.
I don't think there is a way to just see the token and tell from which platform it belongs.
Related Topics
Android - Out of Memory Exception When Creating Bitmap
How to Programmatically Set the Layout_Align_Parent_Right Attribute of a Button in Relative Layout
Android: How to Convert String to Date
How to Find and Turn on Usb Debugging Mode on Nexus 4
Bind/Unbind Service Example (Android)
Broadcastreceiver When Wifi or 3G Network State Changed
The Signing Fingerprint You Specified Is Already Used by Another Android Oauth2 Client
Measuring Text Height to Be Drawn on Canvas ( Android )
Fragment Onresume() & Onpause() Is Not Called on Backstack
Android - Linearlayout Horizontal with Wrapping Children
How to Change the Textcolor on an Android Searchview
How to Convert Views to Bitmaps
Exclude a Class from the Build in Android Studio
Receive Gcm Notification Even When the App Is Closed (Slide/Swiped Away)
What Is the Fastest Way to Scrape HTML Webpage in Android
Android Studio - Unable to Merge from Svn Branch