本文主要是介绍Android快速SDK(23)第三方授权登录库ThirdLogin【肌肉记忆,分钟接入】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码:http://download.csdn.net/detail/huangbin95487710/9260831
依赖包模式
完整运行还需要用到以下依赖包
基于各授权登录SDK再次封装
Android快速SDK(2)View库QuickView
- 淘宝授权登录SDK
- 授权登录支持
- QQ登录
- 微信登录
- 淘宝登录
- 新浪微博登录
- 新特性配置支持
- 配置或设置各种授权登录
- 配置各登录需要的KEY
- 属性
<declare-styleable name="ThirdLogin"><!-- QQ APPID --><attr name="third_qq_appid" format="string" /><!-- QQ SCOPE --><attr name="third_qq_scope" format="string" /><!-- 微信 APPID --><attr name="third_weixin_appid" format="string" /><!-- 微信 SECRET --><attr name="third_weixin_secret" format="string" /><!-- 微信 SCOPE --><attr name="third_weixin_scope" format="string" /><!-- 微博 APPID --><attr name="third_sina_appid" format="string" /><!-- 微博 URL --><attr name="third_sina_url" format="string" /><!-- 微博 SCOPE --><attr name="third_sina_scope" format="string" /><!-- QQ 显示 --><attr name="qq_show" format="boolean" /><!-- 微信 显示 --><attr name="weixin_show" format="boolean" /><!-- 微博 显示 --><attr name="sina_show" format="boolean" /><!-- 淘宝 显示 --><attr name="alipay_show" format="boolean" /><!-- 获取用户资料 --><attr name="is_getuseinfo" format="boolean" /><!-- 返回按键 --><attr name="keycode_back" format="boolean" /></declare-styleable>
- 默认样式
<!-- 自定义登录样式 --><style name="DivThirdLogin"><item name="third_qq_appid">@string/thirdlogin_qq_appid</item><item name="third_qq_scope">@string/thirdlogin_qq_scope</item><item name="third_weixin_appid">@string/thirdlogin_weixin_appid</item><item name="third_weixin_secret">@string/thirdlogin_weixin_secret</item><item name="third_weixin_scope">@string/thirdlogin_weixin_scope</item><item name="third_sina_appid">@string/thirdlogin_sina_appid</item><item name="third_sina_url">@string/thirdlogin_sina_url</item><item name="third_sina_scope">@string/thirdlogin_sina_scope</item><item name="qq_show">true</item><item name="weixin_show">true</item><item name="sina_show">true</item><item name="alipay_show">true</item><item name="is_getuseinfo">true</item><item name="keycode_back">true</item></style>
- AndroidManifest.xml添加配置
<applicationandroid:allowBackup="true"android:theme="@android:style/Theme.NoTitleBar" ><!-- ###################第三方登录################### --><activityandroid:name="com.tencent.connect.common.AssistActivity"android:configChanges="orientation|keyboardHidden"android:screenOrientation="portrait"android:theme="@android:style/Theme.Translucent.NoTitleBar" /><activityandroid: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="tencent801291865" /><!-- 100380359 100381104 801291865 --></intent-filter></activity><!-- ###################第三方登录################### --><!-- ###################淘宝登录################### --><activityandroid:name="app.general.lib.TaoBaoActivity"android:configChanges="orientation|keyboardHidden|navigation"android:screenOrientation="portrait"android:theme="@android:style/Theme.Translucent.NoTitleBar" /><activity android:name="com.alibaba.sdk.android.webview.BaseWebViewActivity" /><activity android:name="com.alibaba.sdk.android.login.ui.LoginWebViewActivity" /><activityandroid:name="com.alibaba.sdk.android.login.ui.QrLoginActivity"android:theme="@style/tae_sdk_login_qr_activity_style" /><!-- ###################淘宝登录################### --></application><!-- ###################第三方登录权限################### --><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><!-- ###################第三方登录权限################### --><!-- ###################淘宝登录权限################### --><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-permission android:name="android.permission.READ_SETTINGS" /><uses-permission android:name="android.permission.WRITE_SETTINGS" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.GET_TASKS" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.CAMERA" /><!-- ###################淘宝登录权限################### -->
- 添加混淆,详见依赖包proguard.cfg
- 复制以下的XML文件到目标项目,在保持ID不变下,可任意更改界面
- thirdlogin.xml
- thirdlogin_frame.xml
- 代码示例
- 布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/ll"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:padding="15dip" ><ScrollViewandroid:id="@+id/scrollView1"android:layout_width="match_parent"android:layout_height="wrap_content" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><Buttonandroid:id="@+id/button1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="15dip"android:text="第三方登录(默认)" /><Buttonandroid:id="@+id/button2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="15dip"android:text="自定义样式" /><Buttonandroid:id="@+id/button3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="15dip"android:text="自定义布局" /><Buttonandroid:id="@+id/button4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="15dip"android:text="对话框样式" /><Buttonandroid:id="@+id/button5"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="15dip"android:text="注销账号" /><includeandroid:layout_width="fill_parent"android:layout_height="wrap_content"layout="@layout/thirdlogin" ></include></LinearLayout></ScrollView></LinearLayout>
- 自定义样式
<?xml version="1.0" encoding="utf-8"?> <resources><!-- 重写样式 --><style name="MyDivThirdLogin1" parent="@style/DivThirdLogin"><item name="weixin_show">false</item></style></resources>
- 代码
package cn.whonow.whonow.third;import General.System.MyLog; import General.ThirdLogin.Third; import General.ThirdLogin.ThirdBase; import General.ThirdLogin.ThirdListener; import General.ThirdLogin.Sina.Data.AccessTokenKeeper; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import cn.whonow.whonow.R;/*** 第三方登录测试* @必须实现ThirdListener接口* @author HuangYi QQ:95487710*/ public class ThirdLoginActivity extends Activity implements ThirdListener {private Third mThird;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.test_thirdlogin);Button button1 = (Button) findViewById(R.id.button1);button1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubThird mThird = new Third(ThirdLoginActivity.this, R.id.ll,ThirdLoginActivity.this);mThird.popupLogin();}});Button button2 = (Button) findViewById(R.id.button2);button2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubThird mThird = new Third(ThirdLoginActivity.this, R.id.ll,R.style.MyDivThirdLogin1, ThirdLoginActivity.this);mThird.popupLogin();}});Button button3 = (Button) findViewById(R.id.button3);button3.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubThird mThird = new Third(ThirdLoginActivity.this, R.id.ll,R.layout.test_thirdlogin_frame, R.style.DivThirdLogin,ThirdLoginActivity.this);mThird.popupLogin();}});Button button4 = (Button) findViewById(R.id.button4);button4.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubThird mThird = new Third(ThirdLoginActivity.this, -1,R.style.MyDivThirdLogin1, ThirdLoginActivity.this);mThird.popupLogin();}});Button button5 = (Button) findViewById(R.id.button5);button5.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// 注销账号Third.doLogout(ThirdLoginActivity.this);AccessTokenKeeper.clear(ThirdLoginActivity.this);mThird.onLoginSina();}});mThird = new Third(this);mThird.setThirdListener(this);mThird.initLogin();}@Overridepublic void onSucess(ThirdBase mThirdBase) {// TODO Auto-generated method stubMyLog.show(this, "登录方式:" + mThirdBase.mThirdType + "\n\r"+ mThirdBase.mNickName);}@Overridepublic void onError(String mError) {// TODO Auto-generated method stubMyLog.show(this, "错误信息:" + mError);}@Overridepublic void onCancel() {// TODO Auto-generated method stub}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (mThird != null) {mThird.onActivityResult(requestCode, resultCode, data);}}@Overridepublic void onDestroy() {super.onDestroy();if (mThird != null) {mThird.onDestroy();}}@Overridepublic void onResume() {super.onResume();if (mThird != null) {mThird.onResume();}}@Overridepublic void onPause() {super.onPause();if (mThird != null) {mThird.onPause();}}}
- 效果图
这篇关于Android快速SDK(23)第三方授权登录库ThirdLogin【肌肉记忆,分钟接入】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!