问题描述
- 使用QQ互联android sdk 回调方法 onComplete 不执行 2C
- MainActivity.java
package com.example.testqq;import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;public class MainActivity extends BaseActivity {
public Button loginBTN;
public TextView loginMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loginBTN= (Button)findViewById(R.id.login);
loginMessage=(TextView) findViewById(R.id.message);
loginBTN.setOnClickListener(new OnClickListener() {public void onClick(View v) { // TODO 自动生成的方法存根 initTencent(); login(); } });}@Overridepublic void showMessage(String msg) { // TODO 自动生成的方法存根 loginMessage.setText(msg);}
}
BaseActivity.java
package com.example.testqq;import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;public abstract class BaseActivity extends Activity {
public static final String AppID = ""222222"";
protected Tencent mTencent;public void initTencent() { mTencent = Tencent.createInstance(AppID this);}public void login(){ mTencent.login(thisall"" new IUiListener() { public void onError(UiError arg0) { // TODO 自动生成的方法存根 showMessage(""Login Error""); Log.i(""111111""22222""); } public void onComplete(Object arg0) { // TODO 自动生成的方法存根 showMessage(""Login success""+arg0.toString()); Log.i(""111111""22222""); } public void onCancel() { // TODO 自动生成的方法存根 showMessage(""Login cancel""); Log.i(""111111""22222""); } });}@Overrideprotected void onActivityResult(int requestCodeint resultCodeIntent data){ super.onActivityResult(requestCode resultCode data); if(mTencent!=null) mTencent.onActivityResult(requestCode resultCode data);}public abstract void showMessage(String msg);
}
布局文件只有一个button和一个textview.
无论是log.i 还是 修改textview 的text值仍然不能调用onComplete .但是我明明已经登录成功了啊.pc电脑都提示我刚才登录了什么什么应用.
解决方案
onActivityResult活动回调那里改一下, mTencent.onActivityResult(requestCode resultCode data);改成mTencent.onActivityResultData(requestCode resultCode data
new BaseUiListener());
解决方案二:
onActivityResult活动回调那里改一下, mTencent.onActivityResult(requestCode resultCode data);改成mTencent.onActivityResultData(requestCode resultCode data
new UiListener());