C'est le premier à utiliser FCM.Firebase (FCM) comment obtenir le jeton
télécharger un échantillon de firebase/quickstart-android et installer la FCM Quickstart.But Je ne peux pas obtenir tout jeton du journal atteint même le bouton LOG TOKEN dans l'application.
Ensuite, j'essaie d'envoyer un message avec la console Firebase et de le définir pour cibler mon nom de package d'application. J'ai reçu un message entrant.
Je veux savoir FCM peut être utilisé? GCM tout va bien.
Solution:
Parce que je ne suis pas un développeur Android, juste un back-end developer.So il me prend un certain temps pour résoudre it.In mon avis, there`re un bug dans l'application de l'échantillon.
code:
RegistrationIntentService.java
public class RegistrationIntentService extends IntentService {
private static final String TAG = "RegIntentService";
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
String token = FirebaseInstanceId.getInstance().getToken();
Log.i(TAG, "FCM Registration Token: " + token);
}
}
MyFirebaseInstanceIDService.java
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
// [START refresh_token]
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
// String refreshedToken = FirebaseInstanceId.getInstance().getToken();
// Log.d(TAG, "Refreshed token: " + refreshedToken);
//
// // TODO: Implement this method to send any registration to your app's servers.
// sendRegistrationToServer(refreshedToken);
//
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
// [END refresh_token]
/**
* Persist token to third-party servers.
* <p>
* 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.
}
}
Ajouter ce dans le MainActivity.java.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
Après faire ci-dessus, vous pouvez obtenir le jeton dans logcat.But enfin je trouve un moyen pratique pour l'obtenir. Il suffit d'utiliser le mode débogage pour installer l'exemple d'application et vous pouvez obtenir le jeton lorsque vous l'installez pour la première fois.
Mais je n t why it can
t imprimer le journal lorsque je l'installe.Peut-être être lié à un système mobile.
Et puis pourquoi je ne peux pas obtenir la notification. FirebaseMessagingService.onMessageReceived n'a pas appelé sendNotification
si le journal est touché, il montrerait le jeton dans l'exemple d'application – Shubhank
Non, l'exemple d'application dit .it n'affichera le jeton dans logcat si je frappe le bouton. Mais je ne trouve rien dans logcat. @ Shubhank – wyx
décommenter ces lignes 'String refreshedToken = FirebaseInstanceId.getInstance(). GetToken(); Log.d (TAG, "Refreshed token:" + refreshedToken); ' – Gaurav