com.tencent.mm.sdk.modelmsg.WXTextObject Java Examples

The following examples show how to use com.tencent.mm.sdk.modelmsg.WXTextObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShareByWeixin.java    From ShareSDK with MIT License 6 votes vote down vote up
/**
 * 构建WXMediaMessage
 *
 * @param bitmap
 */
private WXMediaMessage buildWXMediaMessage(Bitmap bitmap) {
    WXMediaMessage wxMediaMessage = new WXMediaMessage();
    wxMediaMessage.title = data.getTitle();
    wxMediaMessage.description = data.getContent();
    if (TextUtils.isEmpty(data.getUrl())) {
        wxMediaMessage.mediaObject = new WXTextObject(data.getContent());
    } else {
        if (null != bitmap) {
            wxMediaMessage.setThumbImage(getWxShareBitmap(bitmap));
        } else {
            Bitmap defautlBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.share_default);
            if (null != defautlBitmap) {
                wxMediaMessage.setThumbImage(getWxShareBitmap(defautlBitmap));
            }
        }
        wxMediaMessage.mediaObject = new WXWebpageObject(data.getUrl());
    }
    return wxMediaMessage;
}
 
Example #2
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
/**
 *  分享文本
 * @param text
 * @param shareToFriendCircle  是否分享到朋友圈
 */
public void shareText(String text,boolean shareToFriendCircle,IWXShareCallback callback){
    // 初始化一个WXTextObject对象
    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    // 用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    // 发送文本类型的消息时,title字段不起作用
    // msg.title = "Will be ignored";
    msg.description = text;

    // 构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("text"); // transaction字段用于唯一标识一个请求
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    // 调用api接口发送数据到微信
    mWxApi.sendReq(req);
}
 
Example #3
Source File: WeChatHelper.java    From talk-android with MIT License 5 votes vote down vote up
private void sendTextToWX(String text, boolean isTimeline) {
    WXTextObject textObject = new WXTextObject();
    textObject.text = text;
    WXMediaMessage msg = new WXMediaMessage(textObject);
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("text");
    req.message = msg;
    req.scene = isTimeline ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    wxApi.sendReq(req);
}
 
Example #4
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 5 votes vote down vote up
@Override
public void shareText(int platform, String text, Activity activity, ShareListener listener) {
    WXTextObject textObject = new WXTextObject();
    textObject.text = text;

    WXMediaMessage message = new WXMediaMessage();
    message.mediaObject = textObject;
    message.description = text;

    sendMessage(platform, message, buildTransaction("text"));
}
 
Example #5
Source File: Activity_Result.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    StringBuilder stringBuilder = new StringBuilder(title + "\n");
    stringBuilder.append("贷款总额:").append(oneLoanSumTextView.getText().toString()).append("\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("还款总额:").append(oneSumString).append("元\n");
    stringBuilder.append("支付利息:").append(oneInterestString).append("元\n");
    stringBuilder.append("每月还款:").append(oneMonthPayString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("还款总额:").append(twoSumString).append("元\n");
    stringBuilder.append("支付利息:").append(twoInterestString).append("元\n");
    stringBuilder.append("首月还款:").append(twoFistMonthSum).append("元\n");
    stringBuilder.append("每月递减:").append(twoDeltaMonthSum).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #6
Source File: Activity_Result_Combination.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result_Combination.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    DecimalFormat df = new DecimalFormat("#,###.0");

    StringBuilder stringBuilder = new StringBuilder("组合贷款\n");
    stringBuilder.append("贷款总额:").append(df.format(mortgage / 10000)).append("万元\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("商业还款:").append(oneSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(oneInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(oneSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(oneInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(onePayString).append("元\n");
    stringBuilder.append("利息总额:").append(oneInterestString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("商业还款:").append(twoSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(twoInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(twoSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(twoInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(twoPayString).append("元\n");
    stringBuilder.append("利息总额:").append(twoInterestString).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #7
Source File: Activity_Result.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    StringBuilder stringBuilder = new StringBuilder(title + "\n");
    stringBuilder.append("贷款总额:").append(oneLoanSumTextView.getText().toString()).append("\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("还款总额:").append(oneSumString).append("元\n");
    stringBuilder.append("支付利息:").append(oneInterestString).append("元\n");
    stringBuilder.append("每月还款:").append(oneMonthPayString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("还款总额:").append(twoSumString).append("元\n");
    stringBuilder.append("支付利息:").append(twoInterestString).append("元\n");
    stringBuilder.append("首月还款:").append(twoFistMonthSum).append("元\n");
    stringBuilder.append("每月递减:").append(twoDeltaMonthSum).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}
 
Example #8
Source File: Activity_Result_Combination.java    From MortgageCalculator with Apache License 2.0 4 votes vote down vote up
private void share2WeChat(int flag) {
    if (!wxApi.isWXAppInstalled()) {
        Toast.makeText(Activity_Result_Combination.this, "您还未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }

    DecimalFormat df = new DecimalFormat("#,###.0");

    StringBuilder stringBuilder = new StringBuilder("组合贷款\n");
    stringBuilder.append("贷款总额:").append(df.format(mortgage / 10000)).append("万元\n");
    stringBuilder.append("贷款月数:").append(time).append("月\n\n");

    stringBuilder.append("等额本息贷款方式:\n");
    stringBuilder.append("商业还款:").append(oneSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(oneInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(oneSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(oneInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(onePayString).append("元\n");
    stringBuilder.append("利息总额:").append(oneInterestString).append("元\n\n");

    stringBuilder.append("等额本金贷款方式:\n");
    stringBuilder.append("商业还款:").append(twoSumCommString).append("元\n");
    stringBuilder.append("商业利息:").append(twoInterestCommString).append("元\n");
    stringBuilder.append("公积金还款:").append(twoSumHAFString).append("元\n");
    stringBuilder.append("公积金利息:").append(twoInterestHAFString).append("元\n");
    stringBuilder.append("还款总额:").append(twoPayString).append("元\n");
    stringBuilder.append("利息总额:").append(twoInterestString).append("元\n");

    //初始化一个WXTextObject对象,填写分享的文本内容
    WXTextObject textObj = new WXTextObject();
    textObj.text = stringBuilder.toString();

    //用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = "房贷计算结果";

    //构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    //req.transaction = buildTransaction("这是transaction");				//transaction字段用于唯一标识一个请求
    req.message = msg;

    switch (flag){
        case 0:
            //发送给好友
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;

        case 1:
            //发送到朋友圈
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
    }
    wxApi.sendReq(req);
}