我想在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;
}
答案 0 :(得分:0)
只需像这样制作XWalkResponceClient的构造函数
Package [project] for Android (.apk)
现在传递此上下文
Context context
public XWalkResponceClient(Context context)
{
this.context=context;
}