友盟社会化分享

*今天写了个分享用的是友盟的SDK代码很简单不过还是要做个笔记
1.先把要分享的平台添加进来
//添加QQ空间

QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this,constan.qqAppId, constan.qqAppKey);

// 添加微信平台

     UMWXHandler wxHandler = new UMWXHandler(this,constan.weiXingAppID,constan.weiXingAppSecret);

// 添加微信朋友圈

  UMWXHandler wxCircleHandler = new UMWXHandler(this,constan.weiXingAppID,constan.weiXingAppSecret);
       wxCircleHandler.setToCircle(true);

//QQ分享

     UMImage urlImages = new UMImage(this,imagePath);
   UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, constan.qqAppId,constan.qqAppKey);*

//设置微信朋友圈分享内容

  CircleShareContent circleMedia = new CircleShareContent();
       circleMedia.setShareContent(shareContent);
       circleMedia.setTitle(shareTitle);
       circleMedia.setTargetUrl(url);
       circleMedia.setShareImage(urlImages);
       mController.setShareMedia(circleMedia);

//微信好友分享内容

 WeiXinShareContent weixinContent = new WeiXinShareContent();
       weixinContent.setShareContent(shareContent);
       weixinContent.setTitle(shareTitle);
       weixinContent.setShareImage(urlImages);
       weixinContent.setTargetUrl(url);
       mController.setShareMedia(weixinContent);

//QQ空间分享内容

 QZoneShareContent qzone = new QZoneShareContent();
       qzone.setShareContent(shareContent);
       qzone.setTargetUrl(url);
       qzone.setTitle(shareTitle);
       qzone.setShareImage(new UMImage(getApplicationContext(), imagePath));
       mController.setShareMedia(qzone);

//qq好友分享内容

 QQShareContent qqShareContent = new QQShareContent();
       qqShareContent.setShareContent(shareContent);
       qqShareContent.setTitle(shareTitle);
       qqShareContent.setShareImage(new UMImage(getApplicationContext(), imagePath));
       qqShareContent.setTargetUrl(url);
       mController.setShareMedia(qqShareContent);

3.把这段代码加上去吧 虽然不知道是干嘛的:

       qZoneSsoHandler.addToSocialSDK();
       wxHandler.addToSocialSDK();
       wxCircleHandler.addToSocialSDK();
       qqSsoHandler.addToSocialSDK();

4.在结尾写个响应事件:

      mController.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE);
mController.openShare(shape.this, null);

附上完整代码(拿来直接用):

public void setShareContent(String shareTitle,String shareContent,String url,String imagePath) {

//添加QQ空间
QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this,constan.qqAppId, constan.qqAppKey);
 // 添加微信平台
       UMWXHandler wxHandler = new UMWXHandler(this,constan.weiXingAppID,constan.weiXingAppSecret);
       //wxHandler.addToSocialSDK();
       // 添加微信朋友圈
       UMWXHandler wxCircleHandler = new UMWXHandler(this,constan.weiXingAppID,constan.weiXingAppSecret);
       wxCircleHandler.setToCircle(true);
       //QQ分享
       UMImage urlImages = new UMImage(this,imagePath);
    UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, constan.qqAppId,constan.qqAppKey);
//设置微信朋友圈分享内容
       CircleShareContent circleMedia = new CircleShareContent();
       circleMedia.setShareContent(shareContent);
       circleMedia.setTitle(shareTitle);
       circleMedia.setTargetUrl(url);
       circleMedia.setShareImage(urlImages);
       mController.setShareMedia(circleMedia);

       //微信好友分享内容
       WeiXinShareContent weixinContent = new WeiXinShareContent();
       weixinContent.setShareContent(shareContent);
       weixinContent.setTitle(shareTitle);
       weixinContent.setShareImage(urlImages);
       weixinContent.setTargetUrl(url);
       mController.setShareMedia(weixinContent);
       //QQ空间分享内容
       QZoneShareContent qzone = new QZoneShareContent();
       qzone.setShareContent(shareContent);
       qzone.setTargetUrl(url);
       qzone.setTitle(shareTitle);
       qzone.setShareImage(new UMImage(getApplicationContext(), imagePath));
       mController.setShareMedia(qzone);

       //qq好友分享内容
       QQShareContent qqShareContent = new QQShareContent();
       qqShareContent.setShareContent(shareContent);
       qqShareContent.setTitle(shareTitle);
       qqShareContent.setShareImage(new UMImage(getApplicationContext(), imagePath));
       qqShareContent.setTargetUrl(url);
       mController.setShareMedia(qqShareContent);

       qZoneSsoHandler.addToSocialSDK();
       wxHandler.addToSocialSDK();
       wxCircleHandler.addToSocialSDK();
       qqSsoHandler.addToSocialSDK();


mController.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE);
mController.openShare(shape.this, null);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值