先来给大伙看一下集成效果:
下面是详细的集成过程:
首先来到官网:http://www.umeng.com/
选择社会化分享,进入查看这个产品的介绍,下载对应平台的SDK,笔者这里自然是选择Android平台:
笔者集成友盟社会化组件的时候还未更新到4.1,所以使用的4.0版的,点击下载就可以选择你想要集成分享的平台,还有你想要的文档或者Demo:
这些操作都可以自行到官网进行查看,笔者就不再浪费口舌。
下载完后,解压缩可以看到以下目录和文件:
platforms目录下对应了不同的平台的所需要的资源和jar包:
然后选择你想要集成的平台,复制的res和libs到你的目标项目中去:
这个操作做完之后,在AndroidManifest.xml中增加必要的配置:
- <!-- ************************* 分享相关的注册 START **************************** -->
- <!-- 分享内容编辑页 -->
- <activity
- android:name="com.umeng.socialize.view.ShareActivity"
- android:configChanges="orientation|keyboard"
- android:launchMode="singleTask"
- android:noHistory="true"
- android:theme="@style/Theme.UMDialog"
- android:windowSoftInputMode="stateVisible|adjustResize" >
- </activity>
- <!-- 腾讯SSO授权的Activity注册 -->
- <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" />
- <data android:scheme="tencent100424468" />
- </intent-filter>
- </activity>
- <activity
- android:name="com.tencent.connect.common.AssistActivity"
- android:screenOrientation="portrait"
- android:theme="@android:style/Theme.Translucent.NoTitleBar" />
- <!-- 微信回调activity -->
- <activity
- android:name="com.xiaowu.blogclient.umeng.WXEntryActivity"
- android:configChanges="keyboardHidden|orientation|screenSize"
- android:exported="true"
- android:screenOrientation="portrait"
- android:theme="@android:style/Theme.Translucent.NoTitleBar" />
- <!-- 易信回调activity -->
- <activity
- android:name=".yxapi.YXEntryActivity"
- android:configChanges="keyboardHidden|orientation|screenSize"
- android:exported="true"
- android:screenOrientation="portrait"
- android:theme="@android:style/Theme.Translucent.NoTitleBar" />
- <!-- 人人SSO授权所需的OAuthActivity -->
- <activity
- android:name="com.renn.rennsdk.oauth.OAuthActivity"
- android:configChanges="orientation|navigation|keyboardHidden" />
- <!-- facebook相关 -->
- <activity android:name=".activity.FacebookActivity" >
- </activity>
- <activity
- android:name="com.facebook.LoginActivity"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.Translucent.NoTitleBar" />
- <!-- ************************* 分享相关的注册 END **************************** -->
然后在代码中进行如下的初始化操作,小巫已经把各个平台的使用写在以下方法:
- /**
- * @功能描述 : 初始化与SDK相关的成员变量
- */
- private void initConfig() {
- mContext = getActivity();
- mController = UMServiceFactory.getUMSocialService(DESCRIPTOR);
- // 要分享的文字内容
- mShareContent = "小巫CSDN博客客户端,CSDN移动开发专家——IT_xiao小巫的专属客户端,你值得拥有。";
- mController.setShareContent(mShareContent);
- Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
- R.drawable.xiaowu);
- mUMImgBitmap = new UMImage(mContext, bitmap);
- mController.setShareImage(mUMImgBitmap);
- mController.setAppWebSite(""); // 设置应用地址
- // 添加新浪和qq空间的SSO授权支持
- mController.getConfig().setSsoHandler(new SinaSsoHandler());
- // 添加腾讯微博SSO支持
- mController.getConfig().setSsoHandler(new TencentWBSsoHandler());
- // wx967daebe835fbeac是你在微信开发平台注册应用的AppID, 这里需要替换成你注册的AppID
- String appID = "wx880cb2b22509cf25";
- // 添加微信平台
- UMWXHandler wxHandler = new UMWXHandler(getActivity(), appID);
- wxHandler.addToSocialSDK();
- // 支持微信朋友圈
- UMWXHandler wxCircleHandler = new UMWXHandler(getActivity(), appID);
- wxCircleHandler.setToCircle(true);
- wxCircleHandler.addToSocialSDK();
- // 设置微信好友分享内容
- WeiXinShareContent weixinContent = new WeiXinShareContent();
- // 设置分享文字
- weixinContent.setShareContent(mShareContent);
- // 设置title
- weixinContent.setTitle("小巫CSDN博客客户端");
- // 设置分享内容跳转URL
- weixinContent.setTargetUrl("你的http://blog.csdn.net/wwj_748链接");
- // 设置分享图片
- weixinContent.setShareImage(mUMImgBitmap);
- mController.setShareMedia(weixinContent);
- // 设置微信朋友圈分享内容
- CircleShareContent circleMedia = new CircleShareContent();
- circleMedia.setShareContent(mShareContent);
- // 设置朋友圈title
- circleMedia.setTitle("小巫CSDN博客客户端");
- circleMedia.setShareImage(mUMImgBitmap);
- circleMedia.setTargetUrl("你的http://blog.csdn.net/wwj_748链接");
- mController.setShareMedia(circleMedia);
- // 参数1为当前Activity,参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY.
- UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(getActivity(),
- "1102369913", "62ru775qbkentOUp");
- qqSsoHandler.addToSocialSDK();
- // 参数1为当前Activity,参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY.
- QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(getActivity(),
- "1102369913", "62ru775qbkentOUp");
- qZoneSsoHandler.addToSocialSDK();
- // 添加人人网SSO授权功能
- // APPID:201874
- // API Key:28401c0964f04a72a14c812d6132fcef
- // Secret:3bf66e42db1e4fa9829b955cc300b737
- RenrenSsoHandler renrenSsoHandler = new RenrenSsoHandler(getActivity(),
- "271529", "682c45dbdeba4b608922fef124223efb",
- "2c7c3b63f58b4bfcad3665b49e65d47f");
- mController.getConfig().setSsoHandler(renrenSsoHandler);
- // 添加短信
- SmsHandler smsHandler = new SmsHandler();
- smsHandler.addToSocialSDK();
- // 添加email
- EmailHandler emailHandler = new EmailHandler();
- emailHandler.addToSocialSDK();
- QQShareContent qqShareContent = new QQShareContent();
- qqShareContent.setShareContent(mShareContent);
- qqShareContent.setTitle("小巫CSDN博客");
- qqShareContent.setShareImage(mUMImgBitmap);
- qqShareContent.setTargetUrl("http://blog.csdn.net/wwj_748");
- mController.setShareMedia(qqShareContent);
- QZoneShareContent qzone = new QZoneShareContent();
- // 设置分享文字
- qzone.setShareContent(mShareContent);
- // 设置点击消息的跳转URL
- qzone.setTargetUrl("http://blog.csdn.net/wwj_748");
- // 设置分享内容的标题
- qzone.setTitle("小巫CSDN博客");
- // 设置分享图片
- qzone.setShareImage(mUMImgBitmap);
- mController.setShareMedia(qzone);
- }
通过openShare()方法打开分享盘:
- /**
- * 打开分享盘
- */
- private void openShareBoard() {
- mController.openShare(getActivity(), false);
- }
如果使用了SSO授权,有以下代码:
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- /** 使用SSO授权必须添加如下代码 */
- UMSsoHandler ssoHandler = mController.getConfig().getSsoHandler(
- requestCode);
- if (ssoHandler != null) {
- ssoHandler.authorizeCallBack(requestCode, resultCode, data);
- }
- }
这个基本上就是友盟社会化组件的使用方法,具体每个平台涉及到appkey或者appScrent可以到具体平台创建应用获取:
新浪微博 http://open.weibo.com
腾讯微博 http://dev.t.qq.com
QQ空间 http://connect.qq.com/intro/login/
微信好友 http://open.weixin.qq.com
Facebook https://developers.facebook.com
Twitter https://dev.twitter.com
人人网 http://dev.renren.com
开心网 http://open.kaixin001.com
搜狐微博 http://open.t.sohu.com
网易微博 http://open.t.163.com
豆瓣 http://developers.douban.com
有道云笔记 http://note.youdao.com/open/developguide.html#app
印象笔记 https://dev.evernote.com/
Linkedin https://www.linkedin.com/secure/developer?newapp=
FourSquare https://developer.foursquare.com/
搜狐随身看 https://open.sohu.com/
Flickr http://www.flickr.com/services/
Pinterest http://developers.pinterest.com/
Tumblr http://www.tumblr.com/developers
Dropbox https://www.dropbox.com/developers
Instagram http://instagram.com/developer#
VKontakte http://vk.com/dev
腾讯微博 http://dev.t.qq.com
QQ空间 http://connect.qq.com/intro/login/
微信好友 http://open.weixin.qq.com
Facebook https://developers.facebook.com
Twitter https://dev.twitter.com
人人网 http://dev.renren.com
开心网 http://open.kaixin001.com
搜狐微博 http://open.t.sohu.com
网易微博 http://open.t.163.com
豆瓣 http://developers.douban.com
有道云笔记 http://note.youdao.com/open/developguide.html#app
印象笔记 https://dev.evernote.com/
Linkedin https://www.linkedin.com/secure/developer?newapp=
FourSquare https://developer.foursquare.com/
搜狐随身看 https://open.sohu.com/
Flickr http://www.flickr.com/services/
Pinterest http://developers.pinterest.com/
Tumblr http://www.tumblr.com/developers
Dropbox https://www.dropbox.com/developers
Instagram http://instagram.com/developer#
VKontakte http://vk.com/dev