È il mio primo utilizzo di FCM.Firebase (FCM) come ottenere token
scarica un campione dal firebase/quickstart-android e installare il FCM Quickstart.But I `t ottenere qualsiasi token dal registro anche premere il pulsante LOG GETTONE in app.
Quindi provo a inviare un messaggio con la console Firebase e ho impostato il target sul nome del pacchetto dell'app. Ho ricevuto un messaggio in arrivo.
Voglio sapere che è possibile utilizzare FCM? GCM è tutto ok.
Soluzione:
Perché io non sono uno sviluppatore Android, solo un backend developer.So mi ci vuole un po 'di tempo per risolvere it.In mio parere, là `alcuni bug in app campione.
Codice:
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.
}
}
Aggiungi questo nel MainActivity.java.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
Dopo fare in precedenza, è possibile ottenere il token in logcat.But finalmente trovo un modo convenienteper ottenerlo. Basta usare la modalità di debug per installare l'app di esempio ed è possibile ottenere il token quando lo si installa per la prima volta.
Ma io indico t why it can
t stampare il registro quando lo installo. Potrebbe essere correlato al sistema mobile.
E quindi perché non riesco a ottenere la notifica. FirebaseMessagingService.onMessageReceived non ha chiamato sendNotification
se il log viene colpito, sarebbe mostrare il token con esso in app campione – Shubhank
No, l'applicazione del campione ha detto .It mostrare solo il gettone nel logcat se mi ha colpito il tasto. Ma non trovo nulla in logcat. @ Shubhank – wyx
decommenta questa riga 'String refreshedToken = FirebaseInstanceId.getInstance(). GetToken(); Log.d (TAG, "Token aggiornato:" + refreshedToken); ' – Gaurav