android 友盟社会化分享
/** * 获取友盟分享对象 */ public static UMSocialService getShare(Context context, String title, String content, String url, String imgurl, String appID, String appSecret) { if (!isNotNull(title)) { title = " "; } if (!isNotNull(content)) { content = " "; } if (!isNotNull(url)) { url = " "; } if (!isNotNull(imgurl)) { imgurl = " "; } //设置分享界面 UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share"); //删除自带分享 mController.getConfig().removePlatform(SHARE_MEDIA.RENREN, SHARE_MEDIA.DOUBAN, SHARE_MEDIA.TENCENT, SHARE_MEDIA.SINA); // 添加微信平台 UMWXHandler wxHandler = new UMWXHandler(context, appID, appSecret); wxHandler.addToSocialSDK(); // 支持微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(context, appID, appSecret); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); //设置分享内容 //设置微信好友分享内容 WeiXinShareContent weixinContent = new WeiXinShareContent(); weixinContent.setShareContent(content); weixinContent.setTitle(title); //设置分享内容跳转URL weixinContent.setTargetUrl(url); //设置分享图片 weixinContent.setShareImage(new UMImage(context, imgurl)); mController.setShareMedia(weixinContent); //设置微信朋友圈分享内容 CircleShareContent circleMedia = new CircleShareContent(); circleMedia.setShareContent(content); //设置朋友圈title circleMedia.setTitle(title); circleMedia.setShareImage(new UMImage(context, imgurl)); circleMedia.setTargetUrl(url); mController.setShareMedia(circleMedia); return mController; }
然后这样调用
private void share() { StaticMethod.getShare(This, sharetitle, sharecontent, shareurl, shareimgurl, getResources().getString(R.string.share_appid), getResources().getString(R.string.share_secrect)).openShare(This, false); }