onTokenRefresh in FirebaseInstanceIdService viene chiamato solo quando viene generato un nuovo token. Se la tua app è stata precedentemente installata e generato un token, non verrebbe richiamato onTokenRefresh. Prova a disinstallare e reinstallare l'app per forzare la generazione di un nuovo token, in questo modo si invoca onTokenRefresh.
anche essere sicuri che il vostro FirebaseInstanceIdService sia correttamente definito nel AndroidManifest.xml
nel file manifesto.
<service
android:name="com.bnt.etailers.fcm.MyFireBaseInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.bnt.etailers.fcm.GCMNotificationIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
classe FirebaseInstanceIdService
public class MyFireBaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = MyFireBaseInstanceIDService.class.getSimpleName();
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
if (refreshedToken!=null) {
SettingPreferences.setStringValueInPref(this, SettingPreferences.REG_ID, refreshedToken);
}
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
// [END refresh_token]
/**
* Persist token to third-party servers.
*
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}}
classe FirebaseMessagingService.
public class GCMNotificationIntentService extends FirebaseMessagingService {
// Sets an ID for the notification, so it can be updated
public GCMNotificationIntentService() {
super();
}
@Override
public void onMessageReceived(RemoteMessage message) {
}}
fonte
2016-05-26 15:47:38
Possibile duplicato di [Forza FCM di Firebase onTokenRefresh() da chiamare] (http://stackoverflow.com/questions/37454501/firebase-fcm-force-ontokenrefresh-to-be-called) – Machado
Si prega di leggere completamente le domande . Questa domanda non è un duplicato della domanda che hai menzionato. @Machado –