检索cordova上下文会导致:“错误:找不到符号变量cordova”

时间:2018-07-10 16:19:01

标签: android cordova firebase firebase-cloud-messaging

我正在尝试更改插件cordova-plugin-firebase的文件,我专门尝试通过在FirebasePluginMessagingService.java内添加以下代码来更改文件onMessageReceived();

Context context = this.cordova.getActivity().getApplicationContext();
ShortcutBadger.applyCount(context, 13);

但是,每次运行此代码,我都会得到:

error: cannot find symbol variable cordova

我想我已经进口了必要的东西:

package org.apache.cordova.firebase;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.app.Notification;
import android.text.TextUtils;
import android.content.ContentResolver;
import android.graphics.Color;

import me.leolin.shortcutbadger.ShortcutBadger;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.PluginResult;
import org.apache.cordova.CordovaWebView;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.util.Map;
import java.util.Random;

1 个答案:

答案 0 :(得分:1)

您尝试过

this.getApplicationContext()

至少是这样才能在FirebasePluginMessagingService.java文件中获取上下文。