1
case R.id.fenxiang:
addCustomPlatforms();
// 整个平台的Controller,负责管理整个SDK的配置、操作等处理
private UMSocialService mController = UMServiceFactory
.getUMSocialService("com.umeng.share");
private void setShareContent() { 2 3 mController.setShareContent("友盟社会化组件(SDK)让移动应用快速整合社交分享功能"); 4 5 // 设置分享图片, 参数2为图片的url地址 6 UMImage urlImage = new UMImage(DetailsActivity.this, 7 "http://www.umeng.com/images/pic/social/integrated_3.png"); 8 9 // 设置分享图片,参数2为本地图片的资源引用 10 UMImage localImage = new UMImage(DetailsActivity.this, 11 R.drawable.ic_launcher); 12 13 // 设置分享图片,参数2为本地图片的路径(绝对路径) 14 UMImage resImage = new UMImage(DetailsActivity.this, 15 BitmapFactory.decodeResource(getResources(), 16 R.drawable.ic_launcher)); 17 18 // 音乐 19 UMusic uMusic = new UMusic( 20 "http://music.huoxing.com/upload/20130330/1364651263157_1085.mp3"); 21 uMusic.setAuthor("umeng"); 22 uMusic.setTitle("天籁之音"); 23 // 音乐缩略图 24 uMusic.setThumb("http://www.umeng.com/images/pic/social/chart_1.png"); 25 26 // 视频分享 27 UMVideo video = new UMVideo( 28 "http://v.youku.com/v_show/id_XNTE5ODAwMDM2.html?f=19001023"); 29 // 视频缩略图 30 video.setTitle("视频"); 31 video.setThumb("http://www.umeng.com/images/pic/home/social/img-1.png"); 32 33 // 微信分享内容 34 WeiXinShareContent weixinContent = new WeiXinShareContent(); 35 weixinContent.setShareContent("微信分享内容"); 36 weixinContent.setTitle("微信标题"); 37 // weixinContent.setTargetUrl("http://www.umeng.com"); 38 // weixinContent.setShareImage(urlImage); 39 mController.setShareMedia(weixinContent); 40 41 // 设置朋友圈分享的内容 42 CircleShareContent circleMedia = new CircleShareContent(); 43 circleMedia.setShareContent("微信朋友圈分享内容"); 44 circleMedia.setTitle("微信朋友圈内容"); 45 // circleMedia.setTargetUrl("http://www.umeng.com"); 46 // circleMedia.setShareImage(urlImage); 47 // circleMedia.setShareMedia(uMusic); 48 // circleMedia.setShareMedia(video); 49 mController.setShareMedia(circleMedia); 50 51 // 设置人人分享内容 52 RenrenShareContent renrenShareContent = new RenrenShareContent(); 53 renrenShareContent.setShareContent("人人分享内容"); 54 resImage.setTitle("人人标题"); 55 resImage.setThumb("http://www.umeng.com/images/pic/social/integrated_3.png"); 56 renrenShareContent.setShareImage(resImage); 57 renrenShareContent.setAppWebSite("http://www.umeng.com/social"); 58 mController.setShareMedia(renrenShareContent); 59 60 // QQ空间分享 61 QZoneShareContent qzone = new QZoneShareContent(); 62 qzone.setShareContent("QQ空间分享内容"); 63 qzone.setTargetUrl("http://www.umeng.com/social"); 64 qzone.setTitle("QQ空间标题"); 65 qzone.setShareImage(localImage); 66 mController.setShareMedia(qzone); 67 68 // QQ分享 69 QQShareContent qqShareContent = new QQShareContent(); 70 qqShareContent.setShareContent("QQ分享内容"); 71 qqShareContent.setTitle("QQ标题"); 72 qqShareContent.setShareImage(urlImage); 73 qqShareContent.setShareMedia(uMusic); 74 qqShareContent.setTargetUrl("http://www.umeng.com/social"); 75 mController.setShareMedia(qqShareContent); 76 77 // 腾讯微博分享 78 TencentWbShareContent tencent = new TencentWbShareContent(); 79 tencent.setShareContent("腾讯微博分享内容"); 80 // tencent.setShareImage(localImage); 81 tencent.setShareMedia(video); 82 // tencent.setShareMedia(uMusic); 83 tencent.setTitle("腾讯微博"); 84 mController.setShareMedia(tencent); 85 86 // 新浪微博分享 87 SinaShareContent sinaContent = new SinaShareContent(urlImage); 88 sinaContent.setShareContent("新浪微博分享内容"); 89 sinaContent.setShareImage(localImage); 90 sinaContent.setTitle("新浪微博"); 91 mController.setShareMedia(sinaContent); 92 93 } 94 95 private void addWXPlatform() { 96 String appId = "wx967daebe835fbeac"; 97 String appSecret = "5bb696d9ccd75a38c8a0bfe0675559b3"; 98 99 // 添加微信平台 100 UMWXHandler wxHandler = new UMWXHandler(DetailsActivity.this, appId, 101 appSecret); 102 wxHandler.addToSocialSDK(); 103 104 // 支持微信朋友圈 105 UMWXHandler wxCircleHandler = new UMWXHandler(DetailsActivity.this, 106 appId, appSecret); 107 wxCircleHandler.setToCircle(true); 108 wxCircleHandler.addToSocialSDK(); 109 } 110 111 private void addQQQZonePlatform() { 112 // 参数1为当前Activity,参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY. 113 UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(DetailsActivity.this, 114 "100424468", "c7394704798a158208a74ab60104f0ba"); 115 qqSsoHandler.setTargetUrl("http://www.umeng.com"); 116 qqSsoHandler.addToSocialSDK(); 117 118 // 添加QZone平台 119 QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler( 120 DetailsActivity.this, "100424468", 121 "c7394704798a158208a74ab60104f0ba"); 122 qZoneSsoHandler.addToSocialSDK(); 123 } 124 125 private void addCustomPlatforms() { 126 // 添加微信平台 127 addWXPlatform(); 128 // 添加QQ平台 129 addQQQZonePlatform(); 130 mController.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN, 131 SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, 132 SHARE_MEDIA.SINA, SHARE_MEDIA.TENCENT, SHARE_MEDIA.RENREN); 133 134 mController.openShare(DetailsActivity.this, false); 135 } 136 137 }
时间: 2024-10-05 12:01:47