i want to setup firebase inapp messaging on my flutter apps.
first, it need FirebaseInstanceId
as explained here, so i can test send message to my device.
However the document does not tell more detail how to get it on Android, especially on flutter.
any idea ?
Note : someone has claimed that he can use inapp-messaging in flutter, please see here
Thank you in Advance...
The Instance ID API lets you integrate Instance ID with your Android or iOS app. Instance ID provides a unique identifier for each instance of your app and a mechanism to authenticate and authorize actions, like sending messages via Firebase Cloud Messaging.
Firebase Instance ID provides a unique identifier for each app instance and a mechanism to authenticate and authorize actions (example: sending FCM messages). Instance ID is stable except when: App deletes Instance ID. App is restored on a new device. User uninstalls/reinstall the app.
You can run this in your terminal.
adb logcat | grep 'InAppMessaging'
02-26 23:47:44.835 28379 28379 I FIAM.Headless: Starting InAppMessaging runtime with Installation ID dTEmOkEwRzC_xiO8YNPXs0
The Firebase Instance ID can be fetched using -instanceIDWithHandler on iOS or getInstanceId on Android.
At the time of writing, I am not aware of a standalone plugin that does this, meaning that you have two options:
If you go the firebase_messaging route (mind you, it means you're adding another dependency), you can do something like this:
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
and then, somewhere in your code:
var token = await _firebaseMessaging.getToken();
print("Instance ID: $token");
Update
When you call get token, you get something in the following format: NNNNNNN:MMMMMMMMMMMMMMMMMM. Take only the first part before the colon (NNNNNNNN) - this is the instance ID you need to test your In-App Messaging campaign.
To retrieve the FirebaseInstanceId
you need to implement the Firebase In-App messaging SDK and make sure your app connects to Firebase.
Once the app is connected to Firebase it will add the FirebaseInstanceId
to the Android log once the App is run.
In the article you linked Google explains that you can find the FirebaseInstanceId
by looking in the log for the string I/FIAM.Headless: Starting InAppMessaging runtime with Instance ID <YOUR_APP_ID>
.
If you are using Android Studio you should be able to use the logcat
window to browse the logs of the device (while debugging the App). The logcat
window will also allow you to search and filter the logs so it should be relative easy to find the mentioned string.
So in short (in Android Studio):
Logcat
window;I/FIAM.Headless: Starting InAppMessaging runtime with Instance ID
;If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With