FirebaseAnalytics.getAppInstanceId() for android devices does not work
See original GitHub issueDescribe the bug When using your own example, calling FirebaseAnalytics.getAppInstanceId(): Its returning an string like: ‘com.google.android.gms.tasks.zzu@575g1e6’
After checking FirebaseAnalytics class at android folder, I’ve found the problem:
public void getAppInstanceId(PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
return;
}
String instanceId = mFirebaseAnalytics.getAppInstanceId().toString(); // this line isn't returning the expected value
If you read the documentation of FirebaseAnalytics, you will see that getAppInstanceId will return an Task<String> (what explain the answer I am receiving)
How to solve it Replace your method for something like:
@PluginMethod
public void getAppInstanceId(final PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
return;
}
Task<String> task = this.mFirebaseAnalytics.getAppInstanceId();
task.addOnSuccessListener(new OnSuccessListener<String>() {
@Override
public void onSuccess(String string) {
JSObject result = new JSObject();
result.put("instanceId", string);
call.success(result);
}
});
//task.addOnFailureListener(...)
} catch (Exception ex) {
call.error(ex.getLocalizedMessage());
}
}
Its just required to implement the addOnFailureListener to finish it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
FirebaseAnalytics - Google
Clears all analytics data for this app from the device and resets the app ... If your app does not use a distinct...
Read more >Build fails in getAppInstanceId() · Issue #97
Hey, I have same issue with my app. I tried to add @capacitor-community/firebase-analytics@1.0.1-alpha.0 but it does not work. I can notice ...
Read more >FirebaseAnalytics | Google Play services
Clears all analytics data for this app from the device and resets the app ... Passing null indicates that the event has no...
Read more >Get user_pseudo_id from firebase client sdk?
... that I can find in the BigQuery user_pseudo_id column. Example for android: FirebaseAnalytics.getInstance(this).getAppInstanceId().
Read more >capacitor-community/firebase-analytics
Capacitor community plugin for native Firebase Analytics. ... You may need to run File > Sync Project with Gradle Files in order for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the late reply. Version 0.3.2 works perfectly! Thanks for resolving this issue 👍
Thanks for bringing this up again @Franjoo , I’ll see if I can get on it this week.