Download the SDK Tencent did not fully understand, leading to not use = _ =! Hey rookie did not save it
Run the following code when prompted mTencent class instantiation always fail (ie always throws NullPointer exception);
I think it is Tencent.createInstance (APP_ID, this.getApplicationContext ()); the parameters wrong. But do not understand the second parameter write so right, global Context is this? It is best to have a simple Demo for reference, Tencent's too messy.
This third party login class project in a separate Activity, Global Context does not count the total framework of project drawings
behind
public class QQSinaLogin extends Activity implements OnClickListener {
Button QQloginBtn, SinaloginBtn;
public static Tencent mTencent;
private static final String APP_ID = "100489529";
private static final String SCOPE = "get_user_info, get_simple_userinfo, add_share" ;/ / permissions: read user information and share information
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.qqsinalogin);
/ *
* Class SDK references Tencent open access OpenAPI,
* @ Param1 - APP_ID,
* @ Param2 - Global Context
application* /
mTencent = Tencent.createInstance (APP_ID, this.getApplicationContext ());
QQloginBtn = (Button) findViewById (R.id.QQlogin);
SinaloginBtn = (Button) findViewById (R.id.Weibologin);
QQloginBtn.setOnClickListener (this);
}
@ Override
public void onClick (View v) {
switch (v.getId ()) {
case R.id.QQlogin:
onClickLogin ();
break;
}
}
private void onClickLogin () {
if (! mTencent.isSessionValid ()) {
IUiListener listener = new BaseUiListener () {
@ Override
protected void doComplete (JSONObject values) {
/ / TODO: Login successful some processing
}
};
mTencent.login (this, SCOPE, listener);
} Else {
mTencent.logout (this);
}
}
private class BaseUiListener implements IUiListener {
@ Override
public void onComplete (JSONObject response) {
doComplete (response);
}
protected void doComplete (JSONObject values) {}
@ Override
public void onError (UiError e) {}
@ Override
public void onCancel () {}
}
public boolean onKeyDown (int keyCode, KeyEvent event) {/ / Return key to return to Homepage
if (keyCode == KeyEvent.KEYCODE_BACK
&& Event.getAction () == KeyEvent.ACTION_DOWN) {
Intent intent = new Intent (QQSinaLogin.this, Homepage.class);
startActivity (intent);
overridePendingTransition (R.anim.translate_left_enter,
R.anim.holding_anima); / / set the new Activity Activity enter and exit the current animation.
this.finish ();
return true;
}
return super.onKeyDown (keyCode, event);
}
} Framework of the project the following diagram:
Third-party login screen as follows:
Reply:
Add
in the AndroidManifest
android: noHistory = "true"
android: launchMode = "singleTask">
No comments:
Post a Comment