I struggled with this for more than an hour, then I changed the following code and it unexpectedly worked.
handle your refreshedToken as such:
String refreshedToken; try { refreshedToken = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, "Refreshed token: " + refreshedToken); Localytics.setPushRegistrationId(refreshedToken); } catch (Exception e) { Log.d(TAG, "Refreshed token, catch: " + e.toString()); e.printStackTrace(); }
Try adding android: exported = "true"> to MyFirebaseMessagingService and MyFirebaseInstanceIDService in the manifest so that it looks like this:
<service android:name="com.localytics.android.sample.fcm.MyFirebaseMessagingService" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> <service android:name="com.localytics.android.sample.fcm.MyFirebaseInstanceIDService" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service>
Uninstall the application, install again, it worked. Tested on a real device.
android: exported = "true" is the default option, so you can also completely remove it and it will be set to true.
Also, if you want to call onTokenRefresh more explicitly, you can just call it anywhere in your code:
String refreshedToken = FirebaseInstanceId.getInstance().getToken(); Localytics.setPushRegistrationId(refreshedToken);
You no longer need to rely on broadcasting
danjar Mar 23 '18 at 17:00 2018-03-23 17:00
source share