示例代码:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);
// sendRegistrationToServer(token);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
}
@Override
public void onDeletedMessages() {
// ...
}
@Override
public void onMessageSent(String msgId) {
// ...
}
@Override
public void onSendError(String msgId, Exception exception) {
// ...
}
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// sendRegistrationToServer(refreshedToken);
}
}