一個(gè)輕量寂呛、易擴(kuò)展的第三方登錄分享庫(kù),比友盟分享登錄更穩(wěn)定瘾晃,兼容Android7.0贷痪,目前集成了微信、QQ蹦误、新浪微博3個(gè)平臺(tái)的分享劫拢,以及微信登錄
使用步驟: 1:修改主module的build.gradle文件,在android->defaultConfig下增加 manifestPlaceholders = [
QQ_APPKEY? ? ? ? ? ? ? : "",
QQ_APPKEY_VALUE? ? ? ? : "",
WEIXIN_APPKEY? ? ? ? ? : "",
WEIXIN_APPKEY_VALUE? ? : "",
SINA_WEIBO_APPKEY? ? ? : "",
SINA_WEIBO_APPKEY_VALUE: "",
]
2.?在?manifest?清單文件中增加:
android:name="WEIXIN_APPKEY"
android:value="${WEIXIN_APPKEY}"/>
android:name="WEIXIN_APPKEY_VALUE"
android:value="${WEIXIN_APPKEY_VALUE}"/>
android:name="SINA_WEIBO_APPKEY"
android:value="${SINA_WEIBO_APPKEY}"/>
android:name="SINA_WEIBO_APPKEY_VALUE"
android:value="${SINA_WEIBO_APPKEY_VALUE}"/>
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
android:name=".activity.WBShareActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait">
android:name="com.sina.weibo.sdk.component.WeiboSdkBrowser"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:windowSoftInputMode="adjustResize"/>
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true">
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
3.在Application中增加:?
//分享初始化 PlatformInitConfig.initPlatformApp(this, PlatformEnum.TENCENT_WECHAT, "WEIXIN_APPKEY", "WEIXIN_APPKEY_VALUE");?
PlatformInitConfig.initPlatformApp(this, PlatformEnum.TENCENT_QQ, "QQ_APPKEY", "QQ_APPKEY_VALUE");?
PlatformInitConfig.initPlatformApp(this, PlatformEnum.SINA, "SINA_WEIBO_APPKEY", "SINA_WEIBO_APPKEY_VALUE");?
PlatformInitConfig.AppName = "第三方登錄和分享APP"; PlatformInitConfig.AppIcon = "http://content.17donor.com/content/appimage/todayDonorAPPIcon.png";//AppLogo圖片鏈接 PlatformInitConfig.IsShowLog = false;
4.分享后的回調(diào)(最好是在你的BaseActivity中强胰,只有騰訊平臺(tái)需要這樣做舱沧,其他不用):
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//騰訊客戶端的回調(diào)
if (QQShareAction.callback != null) {
Tencent.onActivityResultData(requestCode, resultCode, data, QQShareAction.callback);
QQShareAction.callback = null;
}
}
5.最后的使用(詳見(jiàn)項(xiàng)目中的例子,里面自帶一個(gè)分享面板偶洋,還可以自己自定義):
/**
* 分享功能
*/
public synchronized void shareClick(View view) {
if (popupWindow == null) {
popupWindow = new ShareBoardPopupWindow(this);
ShareModel shareModel = new ShareModel();
shareModel.shareTitle = "分享的標(biāo)題";
shareModel.shareContent = "分享的內(nèi)容";
shareModel.shareImageUrl = "https://bs.sharing8.cn/content/0/album/146857185116207468.png";//分享的圖片路徑
shareModel.shareUrl = "https://bs.sharing8.cn/manage/office/article/detail?articleId=259";//分享的資源URL
popupWindow.setShareData(shareModel);
}
popupWindow.showPopWindow(view);
}
第三方登錄功能:
//回調(diào)
SimpleLoginCallback loginCallback = new SimpleLoginCallback() {
@Override
public void loginSuccess(PlatformEnum platformEnum, WechatUserInfoModel _wechatUserInfoModel) {
wechatUserInfoModel = _wechatUserInfoModel;
Log.d("login_success_info", wechatUserInfoModel.toString());
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO: 2017/3/2 完成微信登錄后的邏輯
}
});
}
};
//觸發(fā)第三方登錄
LoginAction loginAction = new LoginAction(this, PlatformEnum.TENCENT_WECHAT);
loginAction.setLoginCallback(loginCallback);
loginAction.login();