parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.88k stars 735 forks source link

ParsePush token not registered immediately #1071

Closed Azaratur closed 2 years ago

Azaratur commented 3 years ago

Documentation says that onNewToken is called upon the first app start, but that's not true. It's called only when a new token is needed, so if you add ParsePush on an application that already implemented firebase cloud messaging, this method will not be called so ParseFCM.register(token); in ParseFirebaseMessagingService it's not called too.

To fix this we can simply add this on application onCreate: FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> { if (!task.isSuccessful()) { return; } String token = task.getResult(); ParseFCM.register(token); });

Can be this implemented some where in Parse Push library?

azlekov commented 3 years ago

Using the new versions of firebase causes runtime issues because of change of their internal classes and library mismatch.

mtrezza commented 2 years ago

@L3K0V is this resolved via #1095?

azlekov commented 2 years ago

Not yet, maybe I can take this and open PR

azlekov commented 2 years ago

So,

This is the FCM module issue which now is an optional module. I was thinking to resolve this when Parse initialize but... Looking at the source of the FCM module and Firebase documentation, everything is implemented as expected. Firebase also mentioned on which cases the token is refreshed and onNewToken is called.

@Azaratur what you did there is a fix for your case and maybe can help others. I also used it before on some of my projects, but I found that for me occurs only when I develop and the way to fix it is to uninstall the app first and clear the data. If you have more general idea to improve the FCM token retrieval feel free to open a PR.