概述
Android QQ Third party login
- Foreword
- First:APP ID
- Second:DownLoad
- Third:Add Dependecy
- Fourth:Permission
- Sixth:Add Activity And App Id
- Seventh:Edit his own java file
Foreword
Please be quiet, it will be a moment of make Belive B.
Integrated QQ login is an essential part of a project, and today I will record my integration process for more convenient use in future development.
First:APP ID
You need to go to the QQ open platform to create an application, and after success you will get APP ID.
Second:DownLoad
You need to import a jar package and download the address http://wiki.connect.qq.com/sdk%e4%b8%8b%e8%bd%bd
It used to need two jar packages, but now the latest version only needs one.
Third:Add Dependecy
Add a dependency and compile a project
Fourth:Permission
Open AndroidManifest.xml add permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Sixth:Add Activity And App Id
Add Two Activity to AndroidManifest.xml And replace APP ID with its own APP ID
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent1106500653" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
Seventh:Edit his own java file
The key code is:
private static final String APP_ID = "own APP ID";
Tencent mTencent = Tencent.createInstance(APP_ID, MainActivity.this.getApplicationContext());
mTencent.login(MainActivity.this,"all",authorizationListener);
private IUiListener authorizationListener = new IUiListener() {
@Override
public void onComplete(Object response) {
Toast.makeText(MainActivity.this, "Empowerment success", Toast.LENGTH_SHORT).show();
Log.e(TAG, "response:" + response);
JSONObject obj = (JSONObject) response;
try {
String openID = obj.getString("openid");
String accessToken = obj.getString("access_token");
String expires = obj.getString("expires_in");
mTencent.setOpenId(openID);
mTencent.setAccessToken(accessToken, expires);
QQToken qqToken = mTencent.getQQToken();
mUserInfo = new UserInfo(getApplicationContext(), qqToken);
mUserInfo.getUserInfo(loginUiLisener);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(UiError uiError) {
}
@Override
public void onCancel() {
}
};
private IUiListener loginUiLisener = new IUiListener() {
@Override
public void onComplete(Object response) {
Log.e(TAG, "Login Success" + response.toString());
Toast.makeText(MainActivity.this, "Login Success", Toast.LENGTH_SHORT);
JSONObject object = (JSONObject) response;
mNicknameTv.setText("Nickname:" + object.optString("nickname"));
mGenderTv.setText("Gender:" + object.optString("gender"));
Picasso.with(MainActivity.this)
.load(object.optString("figureurl_qq_2"))
.into(mHeadIv);
}
@Override
public void onError(UiError uiError) {
Log.e(TAG, "Login Fail" + uiError.toString());
Toast.makeText(MainActivity.this, "Login Fail", Toast.LENGTH_SHORT);
}
@Override
public void onCancel() {
Log.e(TAG, "Lgoing Cancel");
Toast.makeText(MainActivity.this, "Lgoing Cancel", Toast.LENGTH_SHORT);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_LOGIN) {
Tencent.onActivityResultData(requestCode, resultCode, data, onResultListener);
}
super.onActivityResult(requestCode, resultCode, data);
}
Here our QQ login will be successful and return to our data
So I can see that I am a poor man.
Thank you for your browsing. You need to send me a message from the source code
I wish you no bug in the code, good night!
长路漫漫,菜不是原罪,堕落才是原罪。
我的CSDN:https://blog.csdn.net/wuyangyang_2000
我的简书:https://www.jianshu.com/u/20c2f2c3560a
我的掘金:https://juejin.im/user/58009b94a0bb9f00586bb8a0
我的GitHub:https://github.com/wuyang2000
个人网站:http://www.xiyangkeji.cn
个人app(茜茜)蒲公英连接:https://www.pgyer.com/KMdT
我的微信公众号:茜洋 (定期推送优质技术文章,欢迎关注)
Android技术交流群:691174792
以上文章均可转载,转载请注明原创。
最后
以上就是复杂小伙为你收集整理的Android QQ Third party loginForewordFirst:APP IDSecond:DownLoadThird:Add DependecyFourth:PermissionSixth:Add Activity And App IdSeventh:Edit his own java file的全部内容,希望文章能够帮你解决Android QQ Third party loginForewordFirst:APP IDSecond:DownLoadThird:Add DependecyFourth:PermissionSixth:Add Activity And App IdSeventh:Edit his own java file所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复