1

我想在xwalkview加载中将我的应用程序注册到GCM,但是我无法访问XWalkResponceClient内的GCM的context和getInstance() 。类型GoogleCloudMessaging中的方法getInstance(Context)不适用于参数(XWalkResponceClient)

@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

只是要XWalkResponceClient的构造这样

Context context 
public XWalkResponceClient(Context context) 
{ 

this.context=context; 
} 

现在在这里通过这种背景下

regId = registerGCM(context); 
+0

@ Akshat隐式超级构造XWalkResourceClient()是不确定的。无论如何,都必须明确地调用另一个constructorthis错误 – SwagDevelopers

+0

尝试将上下文传递给此活动或类。 –

相关问题