用 QQAuth 类来实现登录功能。
主要代码如下:
import com.tencent.connect.auth.QQAuth;
import com.tencent.tauth.IUiListener;
import org.json.JSONObject;
import org.json.JSONException;
private QQAuth mQQAuth = null;
private IUiListener mListenerForQQLogin = null;
mQQAuth = QQAuth.createInstance(QQ_APP_ID, (Context)mAppActivity);
mListenerForQQLogin = new IUiListener() {
@Override
public void onCancel() {
}
@Override
public void onComplete(Object jsonObj) {
try {
String openidString = ((JSONObject)jsonObj).getString(“openid”);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(UiError err) {
}
};
if (mQQAuth != null && !mQQAuth.isSessionValid())
{
mQQAuth.login(mAppActivity, “all”, mListenerForQQLogin);
}