问题
Apparently FirebaseInstanceIdService is depricated. So, I'm trying to changed this code:
import androidx.annotation.Nullable;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class InstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(@Nullable String token) {
if (token != null) {
((SubApp) getApplication()).getRepository().registerInstanceId(token);
}
}
}
to the code below and adapt to the new Firebase requirements:
import androidx.annotation.Nullable;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessagingService;
public class InstanceIDService extends FirebaseMessagingService {
@Override
public void onNewToken (@Nullable String token) {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(@Nullable String token) {
if (token != null) {
((SubApp) InstanceIDService.this.getApplication()).getRepository().registerInstanceId(token);
}
}
}
It seems getApplication()
does not work here. Even with getActivity().getApplication()
. The error is:
cannot resolve method
getApplication()
.
Also I have the error below for @override in FirebaseMessagingService:
Method does not override method from superclass
来源:https://stackoverflow.com/questions/61135045/getapplication-in-firebasemessagingservice