Android 在MyFirebaseMessagingService中获取应用程序上下文

Android 在MyFirebaseMessagingService中获取应用程序上下文,android,Android,我需要从MyFirebaseMessagingService类调用一个worker方法,该类接受上下文作为参数。但我无法访问MyFirebaseMessagingService中的应用程序上下文。如何做到这一点 public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = MyFirebaseInstanceIDService.cl

我需要从MyFirebaseMessagingService类调用一个worker方法,该类接受上下文作为参数。但我无法访问MyFirebaseMessagingService中的应用程序上下文。如何做到这一点

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = MyFirebaseInstanceIDService.class.getSimpleName();

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());

        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());


            MessageSender messageSender = new MessageSender();
            messageSender.sendMessage(CONTEXT HERE);

            if (/* Check if data needs to be processed by long running job */ true) {
                // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
                //scheduleJob();
            } else {
                // Handle message within 10 seconds
                //handleNow();
            }

        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }

        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated. See sendNotification method below.
    }
}

FirebaseMessagingService
扩展
服务

Service
扩展
ContextWrapper

ContextWrapper
扩展
Context


所以这也是一个背景,因此,请使用MyFirebaseMessagingService。此或简单的

在firebase Messaging17.3上不再有效。3@RandySugianto来自的“Yuku”仍然有效,实现步骤仍然相同。@Pavneet_Singh我读过,但它不工作,我得到了
android.content.Context android.content.Context.getApplicationContext()'在空对象引用上