Я хочу получить свой токен, и я делаю точно так же, как много примеров говорит о FirebaseMessagingService У меня есть это
@Override
public void onNewToken(String token) {
super.onNewToken(token);
Log.e("Refreshed token:",token);
}
И я получил ошибку
Метод не переопределяет метод из своего суперкласса
и, конечно, super.onNewToken(token)
имеет ошибку
не может решить метод
На моей основной активности у меня есть это внутри OnCreate ()
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MyActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String newToken = instanceIdResult.getToken();
}
});
И ошибки, которые я получаю,:
Невозможно разрешить getInstanceId ()
Невозможно разрешить InstanceIdResult
Невозможно разрешить getToken ()
, и метод выполняетне переопределить метод из его
суперкласс
Обновление
Объявление класса
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = MyFirebaseMessagingService.class.getSimpleName();
private NotificationUtils notificationUtils;
@Override
public void onNewToken(String token) {
super.onNewToken(token);
Log.e("Refreshed token:",token);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
handleNotification(remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
}
Зависимости
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
Обновление v2
public class FirebaseMessagingService extends com.google.firebase.iid.zzb {
private static final java.util.Queue<java.lang.String> zzoma;
public FirebaseMessagingService() { /* compiled code */ }
@android.support.annotation.WorkerThread
public void onMessageReceived(com.google.firebase.messaging.RemoteMessage remoteMessage) { /* compiled code */ }
@android.support.annotation.WorkerThread
public void onDeletedMessages() { /* compiled code */ }
@android.support.annotation.WorkerThread
public void onMessageSent(java.lang.String s) { /* compiled code */ }
@android.support.annotation.WorkerThread
public void onSendError(java.lang.String s, java.lang.Exception e) { /* compiled code */ }
@com.google.android.gms.common.internal.Hide
protected final android.content.Intent zzp(android.content.Intent intent) { /* compiled code */ }
@com.google.android.gms.common.internal.Hide
public final boolean zzq(android.content.Intent intent) { /* compiled code */ }
@com.google.android.gms.common.internal.Hide
public final void handleIntent(android.content.Intent intent) { /* compiled code */ }
static void zzr(android.os.Bundle bundle) { /* compiled code */ }
static boolean zzal(android.os.Bundle bundle) { /* compiled code */ }