getApplication () in FirebaseMessagingService

安稳与你 提交于 2020-06-17 13:01:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!