/** 配置分享平台参数,并设置分享内容</br> */ public void configPlatforms(UMSocialService mController) { // 添加新浪SSO授权 mController.getConfig().setSsoHandler(new SinaSsoHandler()); // 添加QQ、QZone平台 // addQQZonePlatform(activity); UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, Constants.appId, Constants.appKey); qqSsoHandler.setTargetUrl(Constants.shareUrl); qqSsoHandler.addToSocialSDK(); // 添加QZone平台 QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this, Constants.appId, Constants.appKey); qZoneSsoHandler.addToSocialSDK(); // 添加微信、微信朋友圈平台 // addWXPlatform(activity); UMWXHandler wxHandler = new UMWXHandler(this, Constants.APP_ID, Constants.APP_SECRET); wxHandler.addToSocialSDK(); // 支持微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(this, Constants.APP_ID, Constants.APP_SECRET); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); // 设置各平台分享内容 setShareContent(mController); }
private void initData() { String appID = "wxa263da737a20300e"; String appSecret = "381a2fab6466410c674afaa40c77c953"; // 添加微信平台 UMWXHandler wxHandler = new UMWXHandler(getActivity(), appID, appSecret); wxHandler.addToSocialSDK(); // 添加微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(getActivity(), appID, appSecret); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); }
/** 初始化微信分享 */ private void initWeiXinShare() { // wx967daebe835fbeac是你在微信开发平台注册应用的AppID, 这里需要替换成你注册的AppID String appID = "wxf3ff5a169747d2f5"; String appSecret = "14eeda3b22f601ae91bfd34b8d65574d"; // 添加微信平台 UMWXHandler wxHandler = new UMWXHandler(this, appID, appSecret); wxHandler.addToSocialSDK(); // 支持微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(this, appID, appSecret); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); }
/** * @功能描述 : 添加微信平台分享 * * @return */ private void addWXPlatform() { // 注意:在微信授权的时候,必须传递appSecret // wx967daebe835fbeac是你在微信开发平台注册应用的AppID, 这里需要替换成你注册的AppID String appId = "wxbc29ec947c61f0e1"; String appSecret = "3f7f7b0bbf4d48f3dcc2647d95c3c688"; // 添加微信平台 UMWXHandler wxHandler = new UMWXHandler(this, appId, appSecret); wxHandler.addToSocialSDK(); // 支持微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(this, appId, appSecret); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); }
/** * 分享到微信 * * @param context * @param title 标题 * @param content 内容 * @param imageUrl 图片的url * @param TargetUrl 点击跳转的url */ public void shareWX( Context context, String title, String content, String imageUrl, String targetUrl) { // 首先在您的Activity中添加如下成员变量 final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share"); // 设置微信好友分享内容 WeiXinShareContent weixinContent = new WeiXinShareContent(); // 设置分享文字 weixinContent.setShareContent(content); // 设置title weixinContent.setTitle(title); // 设置分享内容跳转URL weixinContent.setTargetUrl(targetUrl); // //设置分享图片 weixinContent.setShareImage(new UMImage(context, imageUrl)); // 设置分享图片, 参数2为图片的url地址 mController.setShareMedia(weixinContent); // 添加微信平台 UMWXHandler wxHandler = new UMWXHandler(context, appId, appSecret); wxHandler.addToSocialSDK(); // 添加微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(context, appId, appSecret); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); mController.postShare( context, SHARE_MEDIA.WEIXIN, new SnsPostListener() { @Override public void onStart() {} @Override public void onComplete(SHARE_MEDIA arg0, int eCode, SocializeEntity arg2) { if (eCode == 200) { } else { String eMsg = ""; if (eCode == -101) { eMsg = "没有授权"; } Log.d("TAG", "分享失败[" + eCode + "] " + eMsg); } } }); }
public static void uMengShare( Activity context, String title, String content, int resId, String imageUrl, Bitmap bitmap) { UMSocialService controlService = UMServiceFactory.getUMSocialService(ConstantS.ID.DESCRIPTOR); controlService.getConfig().setSsoHandler(new SinaSsoHandler()); controlService.getConfig().setSsoHandler(new TencentWBSsoHandler()); UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler( context, ConstantS.AppId.TENCENT_APP_ID, ConstantS.AppId.TENCENT_APP_SECRET); qqSsoHandler.setTargetUrl(context.getString(R.string.share_url)); qqSsoHandler.addToSocialSDK(); SmsHandler smsHandler = new SmsHandler(); smsHandler.addToSocialSDK(); // 添加QZone平台 QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler( context, ConstantS.AppId.TENCENT_APP_ID, ConstantS.AppId.TENCENT_APP_SECRET); qZoneSsoHandler.addToSocialSDK(); UMWXHandler wxHandler = new UMWXHandler(context, ConstantS.AppId.WX_APP_ID, ConstantS.AppId.WX_APP_SECRET); wxHandler.addToSocialSDK(); UMWXHandler wxCircleHandler = new UMWXHandler(context, ConstantS.AppId.WX_APP_ID, ConstantS.AppId.WX_APP_SECRET); wxCircleHandler.setToCircle(true); wxCircleHandler.addToSocialSDK(); UMImage umImage = null; if (resId != 0) { umImage = new UMImage(context, resId); } if (!TextUtils.isEmpty(imageUrl)) { umImage = new UMImage(context, imageUrl); } if (bitmap != null) { umImage = new UMImage(context, bitmap); } SmsShareContent smsShareContent = new SmsShareContent(); smsShareContent.setShareContent(content); smsShareContent.setShareImage(umImage); TencentWbShareContent tencent = new TencentWbShareContent(); tencent.setShareContent(content); tencent.setTargetUrl(context.getString(R.string.share_url)); tencent.setShareImage(umImage); QQShareContent qqShareContent = new QQShareContent(); qqShareContent.setShareContent(content); qqShareContent.setTitle(title); qqShareContent.setTargetUrl(context.getString(R.string.share_url)); qqShareContent.setShareImage(umImage); QZoneShareContent qZoneShareContent = new QZoneShareContent(); qZoneShareContent.setShareContent(content); qZoneShareContent.setTitle(title); qZoneShareContent.setTargetUrl(context.getString(R.string.share_url)); qZoneShareContent.setShareImage(umImage); WeiXinShareContent weiXinShareContent = new WeiXinShareContent(); weiXinShareContent.setShareContent(content); weiXinShareContent.setTitle(title); weiXinShareContent.setTargetUrl(context.getString(R.string.share_url)); weiXinShareContent.setShareImage(umImage); CircleShareContent circleShareContent = new CircleShareContent(); circleShareContent.setShareContent(content); circleShareContent.setTitle(title); circleShareContent.setTargetUrl(context.getString(R.string.share_url)); circleShareContent.setShareImage(umImage); SinaShareContent sinaShareContent = new SinaShareContent(); sinaShareContent.setShareContent(content); sinaShareContent.setShareImage(umImage); sinaShareContent.setTargetUrl(context.getString(R.string.share_url)); sinaShareContent.setTitle(title); controlService.setShareMedia(sinaShareContent); controlService.setShareMedia(weiXinShareContent); controlService.setShareMedia(circleShareContent); controlService.setShareMedia(tencent); controlService.setShareMedia(qqShareContent); controlService.setShareMedia(qZoneShareContent); controlService.setShareMedia(smsShareContent); controlService.openShare(context, false); }
private void configPlatforms() { String targetUrl = "http://www.mckuai.com/thread-" + post.getId() + ".html"; String title = "麦块for我的世界盒子"; String context = post.getTalkTitle(); UMImage image; if (null != post.getMobilePic() && 10 < post.getMobilePic().length()) { image = new UMImage(this, post.getMobilePic()); } else { image = new UMImage(this, R.drawable.icon_share_default); } String appID_QQ = "101155101"; String appAppKey_QQ = "78b7e42e255512d6492dfd135037c91c"; // 添加qq UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, appID_QQ, appAppKey_QQ); qqSsoHandler.setTargetUrl(targetUrl); qqSsoHandler.setTitle(title); qqSsoHandler.addToSocialSDK(); // 添加QQ空间参数 QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this, appID_QQ, appAppKey_QQ); qZoneSsoHandler.setTargetUrl(targetUrl); qZoneSsoHandler.addToSocialSDK(); String appIDWX = "wx49ba2c7147d2368d"; String appSecretWX = "85aa75ddb9b37d47698f24417a373134"; // 添加微信 UMWXHandler wxHandler = new UMWXHandler(this, appIDWX, appSecretWX); wxHandler.setTargetUrl(targetUrl); wxHandler.setTitle(title); wxHandler.showCompressToast(false); wxHandler.addToSocialSDK(); // 添加微信朋友圈 UMWXHandler wxCircleHandler = new UMWXHandler(this, appIDWX, appSecretWX); wxCircleHandler.setToCircle(true); wxCircleHandler.setTargetUrl(targetUrl); wxHandler.showCompressToast(false); wxCircleHandler.setTitle(title); wxCircleHandler.addToSocialSDK(); // 移除多余平台 mShareService.getConfig().removePlatform(SHARE_MEDIA.TENCENT, SHARE_MEDIA.SINA); // 添加内容和图片 mShareService.setShareContent(context); mShareService.setShareMedia(image); }