一个轻量、易扩展的第三方登录分享库,比友盟分享登录更稳定,兼容Android7.0,目前集成了微信、QQ、新浪微博3个平台的分享,以及微信登录
github地址
使用步骤: 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.分享后的回调(最好是在你的BaseActivity中,只有腾讯平台需要这样做,其他不用):
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//腾讯客户端的回调
if (QQShareAction.callback != null) {
Tencent.onActivityResultData(requestCode, resultCode, data, QQShareAction.callback);
QQShareAction.callback = null;
}
}
5.最后的使用(详见项目中的例子,里面自带一个分享面板,还可以自己自定义):
/**
* 分享功能
*/
public synchronized void shareClick(View view) {
if (popupWindow == null) {
popupWindow = new ShareBoardPopupWindow(this);
ShareModel shareModel = new ShareModel();
shareModel.shareTitle = "分享的标题";
shareModel.shareContent = "分享的内容";
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);
}
第三方登录功能:
//回调
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 完成微信登录后的逻辑
}
});
}
};
//触发第三方登录
LoginAction loginAction = new LoginAction(this, PlatformEnum.TENCENT_WECHAT);
loginAction.setLoginCallback(loginCallback);
loginAction.login();