Esempio n. 1
0
  /**
   * 分享到微信
   *
   * @param context
   * @param title 标题
   * @param content 内容
   * @param imageUrl 图片的url
   * @param TargetUrl 点击跳转的url
   */
  public void shareCIRCLE(
      Context context, String title, String content, String imageUrl, String targetUrl) {
    // 首先在您的Activity中添加如下成员变量
    final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");
    // 设置微信朋友圈分享内容
    CircleShareContent circleMedia = new CircleShareContent();
    circleMedia.setShareContent(content);
    // 设置朋友圈title
    circleMedia.setTitle(title);
    //		//设置分享图片
    circleMedia.setShareImage(new UMImage(context, imageUrl));
    circleMedia.setTargetUrl(targetUrl);
    mController.setShareMedia(circleMedia);

    // 添加微信平台
    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_CIRCLE,
        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);
            }
          }
        });
  }
  // 分享
  private void share(String shareContent, String shareTitle, String linkUrl) {
    UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");

    // 朋友圈
    CircleShareContent circleMedia = new CircleShareContent();
    circleMedia.setShareContent(shareContent);
    circleMedia.setTitle(shareTitle);
    circleMedia.setTargetUrl(linkUrl);
    circleMedia.setShareImage(new UMImage(this, R.drawable.share_money_1000_wechat));
    mController.setShareMedia(circleMedia);

    // 分享到QQ空间
    QZoneShareContent qzone = new QZoneShareContent();
    qzone.setShareContent(shareContent);
    qzone.setTitle(shareTitle);
    qzone.setTargetUrl(linkUrl);
    qzone.setShareImage(new UMImage(this, R.drawable.share_money_1000_wechat));
    mController.setShareMedia(qzone);

    mController.getConfig().removePlatform(SHARE_MEDIA.SINA, SHARE_MEDIA.TENCENT);
    mController.getConfig().setPlatformOrder(SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QZONE);
    mController.openShare(this, false);
  }
Esempio n. 3
0
  /** 根据不同的平台设置不同的分享内容</br> */
  public void setShareContent(UMSocialService mController) {
    // 设置分享内容
    // 配置SSO
    mController.getConfig().setSsoHandler(new SinaSsoHandler());
    mController.setShareContent(Constants.shareContent);
    UMImage urlImage = null;
    try {
      urlImage = new UMImage(this, BitmapFactory.decodeStream(getAssets().open("share_icon.jpg")));
      UMImage shareImage =
          new UMImage(this, BitmapFactory.decodeStream(getAssets().open("share.jpg")));
      mController.setShareImage(shareImage);
    } catch (IOException e) {
      e.printStackTrace();
    }
    // 设置朋友圈分享的内容
    CircleShareContent circleMedia = new CircleShareContent();
    circleMedia.setTitle(Constants.wxShareTitle);
    circleMedia.setShareContent(Constants.shareContent);
    circleMedia.setShareImage(urlImage);
    circleMedia.setTargetUrl(Constants.shareUrl);
    mController.setShareMedia(circleMedia);

    // 设置QQ空间分享内容
    QZoneShareContent qzone = new QZoneShareContent();
    Util.shareContent(qzone, urlImage);
    mController.setShareMedia(qzone);

    QQShareContent qqContent = new QQShareContent();
    Util.shareContent(qqContent, urlImage);
    mController.setShareMedia(qqContent);

    // 设置微信分享内容
    WeiXinShareContent weixinContent = new WeiXinShareContent();
    Util.shareContent(weixinContent, urlImage);
    mController.setShareMedia(weixinContent);
  }
Esempio n. 4
0
  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);
  }