Android 封装第三方登陆与分享组件
有任何建议或反馈 请联系: chenjunqi.china@gmail.com
欢迎大家加入 android 开源项目群(369194705)
, 有合适的项目大家一起 fork
;
module
( 可参考: wechat ),理论上只需在对应的 module
中接入第三方服务的接口,即可正常调用; PlatformEnum
中定义对应 module
的 handler
, 同时不要忘记更改 PlatformEnum.getSupportPlatforms()
方法; IPlatform
,构建对应的平台配置类; PlatformConfiguration
中实现 setXXPlatform()
方法, 供客户端传入 appid
与 appsecret
; SnsPlatform
, ShareAction
类; 主要是目前产品还没有需求接入多SnsPlatform, 所以我就留空了~~ :)
SocialAPI service = SocialAPI.getInstance (this);
service.runOauthApply (this, platform, new ISSOHandler.AuthListener () { @Override public void onComplete (PlatformEnum platform, int action, Map<String, String> map) { Log.d (TAG, "[AuthListener] onComplete: platform = " + platform); Log.d (TAG, "[AuthListener] onComplete: action = " + action); Log.d (TAG, "[AuthListener] onComplete: map = " + map); } @Override public void onError (PlatformEnum platform, int action, Throwable throwable) { Log.d (TAG, "[AuthListener] onError: platform = " + platform); Log.d (TAG, "[AuthListener] onError: action = " + action); Log.d (TAG, "[AuthListener] onError: throwable = " + throwable); } @Override public void onCancel (PlatformEnum platform, int action) { Log.d (TAG, "[AuthListener] onCancel: platform = " + platform); Log.d (TAG, "[AuthListener] onCancel: action = " + action); } });
service.runOauthDelete (this, platform, new ISSOHandler.AuthListener () { @Override public void onComplete (PlatformEnum platform, int action, Map<String, String> map) { Log.d (TAG, "[AuthListener] onComplete: platform = " + platform); Log.d (TAG, "[AuthListener] onComplete: action = " + action); Log.d (TAG, "[AuthListener] onComplete: map = " + map); } @Override public void onError (PlatformEnum platform, int action, Throwable throwable) { Log.d (TAG, "[AuthListener] onError: platform = " + platform); Log.d (TAG, "[AuthListener] onError: action = " + action); Log.d (TAG, "[AuthListener] onError: throwable = " + throwable); } @Override public void onCancel (PlatformEnum platform, int action) { Log.d (TAG, "[AuthListener] onCancel: platform = " + platform); Log.d (TAG, "[AuthListener] onCancel: action = " + action); } });
// 构建分享内容 ShareContent shareContent = new ShareAction.Builder () .setTargetUrl ("[A]www.healthbok.com") .setText ("分享内容来自 bookbuf 分享组件.") .setTitle ("分享标题来自 bookbuf 分享组件.") .build (); // 设定分享回调 IShareHandler.ShareListener shareListener = new IShareHandler.ShareListener () { @Override public void onResult (PlatformEnum shareMedia) { Log.d (TAG, "[ShareListener] onResult: shareMedia = " + shareMedia); } @Override public void onError (PlatformEnum shareMedia, Throwable throwable) { Log.d (TAG, "[ShareListener] onError: shareMedia = " + shareMedia + ", throwable = " + throwable); } @Override public void onCancel (PlatformEnum shareMedia) { Log.d (TAG, "[ShareListener] onCancel: shareMedia = " + shareMedia); } }; // 构建分享行为 ShareAction action = new ShareAction (this) .setShareContent (shareContent) .setShareForm ("[B]www.healthbok.com") .setSharePlatform (platform) .setShareListener (shareListener); // 触发分享行为 service.runShare (this, action, action.getShareListener ());