Esempio n. 1
0
  @Override
  protected void shareText(final ShareParamText params) throws ShareException {
    String text = params.getContent();
    if (TextUtils.isEmpty(text)) {
      throw new InvalidParamException("Content is empty or illegal");
    }

    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("textshare");
    req.message = msg;
    req.scene = getShareType();
    shareOnMainThread(req);
  }
  @Override
  public void onClick(View arg0) {
    switch (arg0.getId()) {
      case R.id.btn_back:
        finish();
        break;
      case R.id.btn_newsdalycomment_add:
        addComment();
        break;
      case R.id.btn_newsdayly_share:
        // 启动微信
        // Toast.makeText(this, String.valueOf(api.openWXApp()),
        // Toast.LENGTH_LONG)
        // .show();
        // 发送文本到朋友圈
        //
        // String text = "application test";
        // WXTextObject textObj = new WXTextObject();
        // textObj.text = text;
        //
        // WXMediaMessage msg = new WXMediaMessage(textObj);
        // msg.mediaObject = textObj;
        // msg.description = text;
        //
        // SendMessageToWX.Req req = new SendMessageToWX.Req();
        // req.transaction = String.valueOf(System.currentTimeMillis());
        // req.message = msg;
        // req.scene = SendMessageToWX.Req.WXSceneTimeline;
        //
        // api.sendReq(req);

        // Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
        // R.drawable.ic_seehdu);
        // WXImageObject imgobj = new WXImageObject(bitmap);
        // WXMediaMessage msg = new WXMediaMessage();
        // msg.mediaObject = imgobj;
        // Bitmap thumbitmap = Bitmap.createScaledBitmap(bitmap, 120, 150,
        // true);
        // bitmap.recycle();
        // msg.thumbData = bmpToArray(thumbitmap, true);
        // SendMessageToWX.Req req = new SendMessageToWX.Req();
        // req.transaction = String.valueOf(System.currentTimeMillis());
        // req.message = msg;
        // req.scene = SendMessageToWX.Req.WXSceneTimeline;
        // api.sendReq(req);
        //
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = surl;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = stitle;
        msg.description = "application test";
        msg.mediaObject = webpage;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_seehdu);
        Bitmap thumbitmap = Bitmap.createScaledBitmap(bitmap, 120, 150, true);
        bitmap.recycle();
        msg.thumbData = bmpToArray(thumbitmap, true);
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = SendMessageToWX.Req.WXSceneTimeline;

        api.sendReq(req);
    }
  }