/**
   * 向指定平台分享内容
   *
   * <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;
  }
Exemple #2
0
 @Override
 public void onClick(View v) {
   String sharedUrl = Constants.PrefixShareUrl + String.valueOf(app.getId());
   switch (v.getId()) {
     case R.id.wechatcomment:
       ShareParams wxcomment = new ShareParams();
       wxcomment.setTitle("请下载我的App");
       wxcomment.setText("我们这里有最精彩的应用,快快来加入我们吧!");
       wxcomment.setUrl(sharedUrl);
       wxcomment.setImageUrl(app.getIcon());
       wxcomment.setShareType(Platform.SHARE_WEBPAGE);
       Platform wc = ShareSDK.getPlatform(WechatMoments.NAME);
       wc.share(wxcomment);
       this.dismiss();
       break;
     case R.id.wechat:
       ShareParams wechat = new ShareParams();
       wechat.setTitle("请下载我的App");
       wechat.setText("我们这里有最精彩的应用,快快来加入我们吧!");
       wechat.setUrl(sharedUrl);
       wechat.setImageUrl(app.getIcon());
       wechat.setShareType(Platform.SHARE_WEBPAGE);
       Platform we = ShareSDK.getPlatform(Wechat.NAME);
       we.share(wechat);
       this.dismiss();
       break;
     case R.id.sina:
       ShareParams sinasp = new ShareParams();
       sinasp.setText("请下载我的App。  " + sharedUrl);
       sinasp.setImageUrl(app.getIcon());
       // sinasp.setImageData(DrawableStringUtils.stringtoBitmap(selectedApp.getDrawableString()));
       Platform sn = ShareSDK.getPlatform(SinaWeibo.NAME);
       sn.share(sinasp);
       this.dismiss();
       break;
   }
 }
  // #endif
  public boolean share(Platform plat, HashMap<String, Object> data) {
    if (plat == null || data == null) {
      return false;
    }

    Platform.ShareParams sp = null;
    try {
      sp = getShareParams(plat, data);
    } catch (Throwable t) {
      sp = null;
    }

    if (sp != null) {
      if (customizeCallback != null) {
        customizeCallback.onShare(plat, sp);
      }
      plat.share(sp);
    }
    return true;
  }