*今天写了个分享用的是友盟的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);
}