Android应用程序想使用微信、微信朋友圈、QQ或者QQ空间分享都比较常见,但是配置非常繁琐,就算是使用友盟也一样。
申请地址:https://open.weixin.qq.com
需要的基本信息:包名+MD5签名
获得AppID以供使用。吐槽一下,这里的应用签名是指MD5签名,那特么的倒是写清楚啊,QQ和百度地图是要求SHA1签名,QQ和新浪微博要求的是MD5签名,这可真是无聊。
申请地址:http://connect.qq.com/
需要的基本信息:包名+sha1签名
获得APP ID以及APP KEY以供使用。这里不得不吐槽一下,申请QQ认证的时候,apk的下载地址是必须填写的,但是还没有完成QQ分享集成的话,应用如何提交应用市场?反过来,不提交应用市场如何获得下载地址?所以,这就是个逗比。
申请地址:http://open.weibo.com/
需要的基本信息:包名+MD5签名
获得APP ID以及App Secret以供使用。吐槽:呵呵
社会化分享-》设置-》自定义配置
<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" /> <!-- xxxxxx,如果你使用的公用账号,则不需要修改;否则修改成你在QQ开放平台申请的 APP ID --> <data android:scheme="tencent刚刚获得的QQ appId" /> </intent-filter> </activity>
MSocialService mUMSocialService = UMServiceFactory.getUMSocialService("com.umeng.share", RequestType.SOCIAL); mUMSocialService.getConfig().supportWXPlatform(act, weixinAppId, contentUrl); WeiXinShareContent media = new WeiXinShareContent(new UMImage(getActivity(), drawableId)); media.setTitle(titleString); media.setShareContent(contentString); media.setTargetUrl(targetUrl); mUMSocialService.setShareMedia(media); mUMSocialService.postShare(getSelfContext(), SHARE_MEDIA.WEIXIN, new SnsPostListener() { @Override public void onStart() { } @Override public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) { } });
UMSocialService mUMSocialService = UMServiceFactory.getUMSocialService("com.umeng.share", RequestType.SOCIAL); mUMSocialService.getConfig().supportWXPlatform(act, weixinAppId, contentUrl); mUMSocialService.getConfig().supportWXCirclePlatform(act, weixinAppId, contentUrl); CircleShareContent media = new CircleShareContent(new UMImage(getActivity(), drawableId)); media.setTitle(titleString); media.setShareContent(contentString); media.setTargetUrl(targetUrl); mUMSocialService.setShareMedia(media); mUMSocialService.postShare(getSelfContext(), SHARE_MEDIA.WEIXIN_CIRCLE, new SnsPostListener() { @Override public void onStart() { } @Override public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) { } });
UMSocialService mUMSocialService = UMServiceFactory.getUMSocialService("com.umeng.share", RequestType.SOCIAL); mUMSocialService.getConfig().supportQQPlatform(act, QQAppId, QQAppKey, contentUrl); QQShareContent qqShareContent = new QQShareContent(); qqShareContent.setShareContent(contentString); qqShareContent.setTitle(titleString); qqShareContent.setTargetUrl(targetUrl); mUMSocialService.setShareMedia(qqShareContent); mUMSocialService.postShare(getSelfContext(), SHARE_MEDIA.QQ, new SnsPostListener() { @Override public void onStart() { } @Override public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) { } });
UMSocialService mUMSocialService = UMServiceFactory.getUMSocialService("com.umeng.share", RequestType.SOCIAL); mUMSocialService.getConfig().supportQQPlatform(act, QQAppId, QQAppKey, contentUrl); QZoneShareContent qZoneShareContent = new QZoneShareContent(); qZoneShareContent.setShareContent(contentString); qZoneShareContent.setTitle(titleString); qZoneShareContent.setTargetUrl(targetUrl); mUMSocialService.setShareMedia(qZoneShareContent); mUMSocialService.postShare(getSelfContext(), SHARE_MEDIA.QZONE, new SnsPostListener() { @Override public void onStart() { } @Override public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) { } });
UMSocialService mUMSocialService = UMServiceFactory.getUMSocialService("com.umeng.share", RequestType.SOCIAL); mUMSocialService.setShareContent(contentString); mUMSocialService.postShare(getSelfContext(), SHARE_MEDIA.SINA, new SnsPostListener() { @Override public void onStart() { } @Override public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) { } });
主要是代码设置支持平台的代码有改变,比如:
// 添加微信平台 UMWXHandler wxHandler = new UMWXHandler(getActivity(),appId,appSecret); wxHandler.addToSocialSDK(); // 添加微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(getActivity(),appId,appSecret); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK();
其他可以参照具体文档
Android分享 Q群:315658668