Beispiel #1
0
  /**
   * 分享到QQ
   *
   * @param context
   * @param title 标题
   * @param content 内容
   * @param imageUrl 图片的url
   * @param TargetUrl 点击跳转的url
   */
  public void shareQQ(
      Activity activity, String title, String content, String imageUrl, String targetUrl) {
    UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(activity, "1105114003", "KLbzI6NDcNbSZHwg");
    qqSsoHandler.addToSocialSDK();

    // 首先在您的Activity中添加如下成员变量
    final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");

    // 设置微信朋友圈分享内容
    QQShareContent qqShareContent = new QQShareContent();
    qqShareContent.setShareContent(content);
    // 设置朋友圈title
    qqShareContent.setTitle(title);
    //		//设置分享图片
    qqShareContent.setShareImage(new UMImage(activity, imageUrl));
    qqShareContent.setTargetUrl(targetUrl);
    mController.setShareMedia(qqShareContent);

    mController.postShare(
        activity,
        SHARE_MEDIA.QQ,
        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);
            }
          }
        });
  }
Beispiel #2
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);
  }
  private void setShareContent() {

    // 配置SSO
    mController.getConfig().setSsoHandler(new SinaSsoHandler());
    mController.getConfig().setSsoHandler(new TencentWBSsoHandler());

    QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this, "1103176396", "iY2uCRqXmaooIL7b");
    qZoneSsoHandler.addToSocialSDK();
    mController.setShareContent(
        "优体教练,三分钟让你淘到最好的教练。http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");

    UMImage localImage = new UMImage(this, R.drawable.sp_head);
    UMImage urlImage = new UMImage(this, "http://www.umeng.com/images/pic/social/integrated_3.png");
    // UMImage resImage = new UMImage(getActivity(), R.drawable.icon);

    WeiXinShareContent weixinContent = new WeiXinShareContent();
    weixinContent.setShareContent(
        "优体教练,三分钟让你淘到最好的教练。http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");
    weixinContent.setTitle("优体教练");
    weixinContent.setTargetUrl(
        "http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");
    weixinContent.setShareMedia(urlImage);
    mController.setShareMedia(weixinContent);

    SnsPostListener mSnsPostListener =
        new SnsPostListener() {

          @Override
          public void onStart() {}

          @Override
          public void onComplete(SHARE_MEDIA platform, int stCode, SocializeEntity entity) {
            if (stCode == 200) {
              Toast.makeText(CourseDetailActivity.this, "分享成功.......", Toast.LENGTH_SHORT).show();
            } else {
              Toast.makeText(
                      CourseDetailActivity.this,
                      "分享失败 : error code : " + stCode,
                      Toast.LENGTH_SHORT)
                  .show();
            }
          }
        };
    mController.registerListener(mSnsPostListener);

    // 设置朋友圈分享的内容
    CircleShareContent circleMedia = new CircleShareContent();
    circleMedia.setShareContent(
        "优体教练,三分钟让你淘到最好的教练。http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");
    circleMedia.setTitle("优体教练");
    circleMedia.setShareMedia(urlImage);
    // circleMedia.setShareMedia(uMusic);
    // circleMedia.setShareMedia(video);
    circleMedia.setTargetUrl("http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");
    mController.setShareMedia(circleMedia);

    UMImage qzoneImage =
        new UMImage(this, "http://www.umeng.com/images/pic/social/integrated_3.png");
    qzoneImage.setTargetUrl("http://www.umeng.com/images/pic/social/integrated_3.png");

    // 设置QQ空间分享内容
    QZoneShareContent qzone = new QZoneShareContent();
    qzone.setShareContent("share test");
    qzone.setTargetUrl("http://www.umeng.com");
    qzone.setTitle("QZone title");
    qzone.setShareMedia(urlImage);
    //			        qzone.setShareMedia(uMusic);
    mController.setShareMedia(qzone);

    QQShareContent qqShareContent = new QQShareContent();
    //			        qqShareContent.setShareContent("来自友盟社会化组件(SDK)让移动应用快速整合社交分享功能 -- QQ");
    qqShareContent.setTitle("hello, title");
    qqShareContent.setTargetUrl(
        "http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");
    mController.setShareMedia(qqShareContent);

    SinaShareContent sinaContent = new SinaShareContent();
    sinaContent.setShareContent(
        "优体教练,三分钟让你淘到最好的教练。http://wtapp.yoti.cn/index.php?m=Share&a=socialdetail&social_id=80");
    mController.setShareMedia(sinaContent);
  }