コード例 #1
0
  /**
   * 向指定平台分享内容
   *
   * <p><b>注意:</b><br>
   * 参数data的键值需要严格按照{@link ShareParams}不同子类具体字段来命名, 否则无法反射此字段,也无法设置其值。
   */
  public boolean share(Platform plat, HashMap<String, Object> data) {
    if (plat == null || data == null) {
      return false;
    }

    try {
      String imagePath = (String) data.get("imagePath");
      Bitmap viewToShare = (Bitmap) data.get("viewToShare");
      if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) {
        String path = R.getCachePath(plat.getContext(), "screenshot");
        File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
        FileOutputStream fos = new FileOutputStream(ss);
        viewToShare.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        data.put("imagePath", ss.getAbsolutePath());
      }
    } catch (Throwable t) {
      t.printStackTrace();
      return false;
    }

    ShareParams sp = new ShareParams(data);
    if (customizeCallback != null) {
      customizeCallback.onShare(plat, sp);
    }

    plat.share(sp);
    return true;
  }
コード例 #2
0
  /** 判断指定平台是否使用客户端分享 */
  public static boolean isUseClientToShare(String platform) {
    if ("Wechat".equals(platform)
        || "WechatMoments".equals(platform)
        || "WechatFavorite".equals(platform)
        || "ShortMessage".equals(platform)
        || "Email".equals(platform)
        || "GooglePlus".equals(platform)
        || "QQ".equals(platform)
        || "Pinterest".equals(platform)
        || "Instagram".equals(platform)
        || "Yixin".equals(platform)
        || "YixinMoments".equals(platform)
        || "QZone".equals(platform)
        || "Mingdao".equals(platform)
        || "Line".equals(platform)
        || "KakaoStory".equals(platform)
        || "KakaoTalk".equals(platform)
        || "Bluetooth".equals(platform)
        || "WhatsApp".equals(platform)
        || "BaiduTieba".equals(platform)
        || "Laiwang".equals(platform)
        || "LaiwangMoments".equals(platform)) {
      return true;
    } else if ("Evernote".equals(platform)) {
      Platform plat = ShareSDK.getPlatform(platform);
      if ("true".equals(plat.getDevinfo("ShareByAppClient"))) {
        return true;
      }
    } else if ("SinaWeibo".equals(platform)) {
      Platform plat = ShareSDK.getPlatform(platform);
      if ("true".equals(plat.getDevinfo("ShareByAppClient"))) {
        Intent test = new Intent(Intent.ACTION_SEND);
        test.setPackage("com.sina.weibo");
        test.setType("image/*");
        ResolveInfo ri = plat.getContext().getPackageManager().resolveActivity(test, 0);
        return (ri != null);
      }
    }

    return false;
  }