GoogleCloudMessaging类型中的getInstance(Context)方法不适用于参数(XWalkResponceClient)

时间:2016-04-28 12:09:11

标签: android google-cloud-messaging android-context crosswalk

我想在xwalkview加载时将我的应用程序注册到GCM,但是我无法在XWalkResponceClient中访问GCM的上下文和getInstance()。

@Override
public void onLoadStarted(XWalkView view, String url) {
  super.onLoadStarted(view, url);
  if (TextUtils.isEmpty(regId)) {
        regId = registerGCM();
        Log.d("RegisterActivity", "GCM RegId: " + regId);
    } else {
        Toast.makeText(getApplicationContext(),
                "Already Registered with GCM Server!",
                Toast.LENGTH_LONG).show();
    }
}

public String registerGCM() {

    gcm = GoogleCloudMessaging.getInstance(this);
    regId = getRegistrationId(context);
    System.out.println("Inside registerGCM method"+regId);
    if (TextUtils.isEmpty(regId)) {

        registerInBackground();

        Log.d("RegisterActivity",
                "registerGCM - successfully registered with GCM server - regId: "
                        + regId);
    } else {
        Toast.makeText(getApplicationContext(),
                "RegId already available. RegId: " + regId,
                Toast.LENGTH_LONG).show();
    }
    return regId;
} 

1 个答案:

答案 0 :(得分:0)

只需像这样制作XWalkResponceClient的构造函数

Package [project] for Android (.apk)

现在传递此上下文

Context context
public XWalkResponceClient(Context context)
{

this.context=context;
}