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

The following examples show how to use com.tencent.mm.sdk.modelmsg.WXMediaMessage. 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: WeChatShareProxy.java    From ESSocialSDK with Apache License 2.0 6 votes vote down vote up
public static void shareToWeChatTimeline(final Context context, final String appId, final String title, final String url,
                                         final String thumbnail, final IWXShareCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeChatShareProxy.mCallback = callback;
            WXWebpageObject webpage = new WXWebpageObject();
            webpage.webpageUrl = url;
            WXMediaMessage msg = new WXMediaMessage(webpage);
            msg.title = title;
            byte[] thumb = SocialUtils.getHtmlByteArray(thumbnail);
            if (null != thumb)
                msg.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                msg.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = SocialUtils.buildTransaction("webpage");
            req.message = msg;
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            WeChat.getIWXAPIInstance(context, appId).sendReq(req);
        }
    }).start();

}
 
Example #2
Source File: WeChatShareProxy.java    From ESSocialSDK with Apache License 2.0 6 votes vote down vote up
public static void shareToWeChat(final Context context, final String appId, final String title, final String desc,
                                 final String url, final String thumbnail, final IWXShareCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeChatShareProxy.mCallback = callback;
            WXWebpageObject webpage = new WXWebpageObject();
            webpage.webpageUrl = url;
            WXMediaMessage msg = new WXMediaMessage(webpage);
            msg.title = title;
            msg.description = desc;
            byte[] thumb = SocialUtils.getHtmlByteArray(thumbnail);
            if (null != thumb)
                msg.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                msg.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = SocialUtils.buildTransaction("webpage");
            req.message = msg;
            req.scene = SendMessageToWX.Req.WXSceneSession;
            WeChat.getIWXAPIInstance(context, appId).sendReq(req);
        }
    }).start();

}
 
Example #3
Source File: WXEntryActivity.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void a(com.tencent.mm.sdk.modelmsg.ShowMessageFromWX.Req req)
{
    Log.d("chenee", "goto show............... msg");
    WXMediaMessage wxmediamessage = req.message;
    WXAppExtendObject wxappextendobject = (WXAppExtendObject)wxmediamessage.mediaObject;
    StringBuffer stringbuffer = new StringBuffer();
    stringbuffer.append("---extInfo(uid): ");
    stringbuffer.append(wxappextendobject.extInfo);
    stringbuffer.append("\n");
    stringbuffer.append("---description: ");
    stringbuffer.append(wxmediamessage.description);
    stringbuffer.append("\n");
    stringbuffer.append("---filePath: ");
    stringbuffer.append(wxappextendobject.filePath);
    b.setText((new StringBuilder()).append(wxmediamessage.title).append("\n").append(stringbuffer.toString()).toString());
}
 
Example #4
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
public void shareWebUrlWithIcon(Bitmap icon, String shareUrl, String title, String desc,
                              boolean shareToFriendCircle, IWXShareCallback callback) {
    final String id = buildTransaction("web_url");
    WXWebpageObject webObj = new WXWebpageObject();
    webObj.webpageUrl = shareUrl;
    webObj.extInfo = "this is extInfo";

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = webObj;
    msg.title = title;
    msg.description = desc;
    msg.setThumbImage(icon);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = id;
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    mWxApi.sendReq(req);
}
 
Example #5
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
/***
 * @param path  the local image path
 */
public void shareImageByPath(String path,String title ,String desc,boolean shareToFriendCircle,IWXShareCallback callback){
    WXImageObject imgObj = new WXImageObject();
    imgObj.setImagePath(path);

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    msg.title = title;
    msg.description = desc;

   // Bitmap bmp = BitmapFactory.decodeFile(path);
    Bitmap bmp = new ImageParser(0,0).parseToBitmap(path);
    Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
    bmp.recycle();
    msg.thumbData = Util.bitampToByteArray(thumbBmp);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("img");
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    mWxApi.sendReq(req);
}
 
Example #6
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 #7
Source File: UserInfoActivity.java    From WeGit with Apache License 2.0 6 votes vote down vote up
private void test() {
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    WXImageObject imgObj = new WXImageObject(bmp);

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;

    Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 200, 200, true);
    bmp.recycle();
    msg.thumbData = BitmapUtils.bmpToByteArray(thumbBmp, true);  //

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = System.currentTimeMillis() + "";
    req.message = msg;
    req.scene = SendMessageToWX.Req.WXSceneSession;
    api.sendReq(req);
}
 
Example #8
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 #9
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 #10
Source File: ShareActivity.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private boolean a(String s1, boolean flag)
{
    if (!t.isWXAppInstalled())
    {
        CustomToast.makeText(this, 0x7f0d017d, 0).show();
        return false;
    }
    WXImageObject wximageobject = new WXImageObject();
    wximageobject.setImagePath(s1);
    android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
    options.inSampleSize = 4;
    M = BitmapFactory.decodeFile(s1, options);
    WXMediaMessage wxmediamessage = new WXMediaMessage();
    wxmediamessage.mediaObject = wximageobject;
    wxmediamessage.title = v;
    wxmediamessage.description = w;
    if (M != null)
    {
        wxmediamessage.setThumbImage(M);
    }
    com.tencent.mm.sdk.modelmsg.SendMessageToWX.Req req = new com.tencent.mm.sdk.modelmsg.SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = wxmediamessage;
    int i1 = 0;
    if (flag)
    {
        i1 = 1;
    }
    req.scene = i1;
    return t.sendReq(req);
}
 
Example #11
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected SendMessageToWX.Req doInBackground(Object... params) {
    final String url = (String) params[0];
    final String title = (String)params[1];
    final String desc = (String)params[2];
    final boolean shareToFriendCircle = (Boolean)params[3];
    final IWXShareCallback callback = (IWXShareCallback)params[4];

    WXImageObject imgObj = new WXImageObject();
    imgObj.imageUrl = url;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    msg.title = title;
    msg.description = desc;

    final String transaction = buildTransaction("img");
    mCallbackMap.put(transaction.hashCode(), callback);
    try {
        Bitmap bmp = new ImageParser(0,0).parseToBitmap(IoUtil.getBytesFromStreamAndClose(
                new URL(url).openStream()));
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
        bmp.recycle();
        msg.thumbData =  Util.bitampToByteArray(thumbBmp);

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = transaction;
        req.message = msg;
        req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline
                : SendMessageToWX.Req.WXSceneSession;
        return req ;
    } catch (IOException e) {
        e.printStackTrace();
    }
    SendMessageToWX.Req req2 = new SendMessageToWX.Req();
    req2.transaction = transaction;
    req2.message = null;
    return req2;
}
 
Example #12
Source File: SharePopWindow.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
/**
 * 分享到微信朋友或者朋友圈
 * @param scene 标记是发送朋友圈还是微信好友
 */
private void share2WeiXin(int scene) {
	if(!api.isWXAppInstalled()) {
		if(scene == SendMessageToWX.Req.WXSceneSession) {
			ToastUtils.showMessageInCenter(context, "您没有安装【微信】\n安装后才能分享到微信好友");
		} else {
			ToastUtils.showMessageInCenter(context, "您没有安装【微信】\n安装后才能分享到朋友圈");
		}
	}
	WXWebpageObject webpage = new WXWebpageObject();
	webpage.webpageUrl = targetUrl + mJoke.getId();
	WXMediaMessage msg = new WXMediaMessage(webpage);
	Bitmap thumb = null;
	switch (mJoke.getType()) {
	case Joke.TYPE_QUSHI:
		msg.title = context.getString(R.string.share_title_qushi);
		msg.description = mJoke.getContent();
		thumb = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
		break;
	case Joke.TYPE_QUTU:
		msg.title = context.getString(R.string.share_title_qutu);
		msg.description = mJoke.getTitle();
		//微信分享缩略图最大不能超过32K,否则无法调开微信界面
		thumb = BitmapUtil.getThumbBitmapFromCache(mJoke.getImgUrl(), 100, 100);
		break;
	case Joke.TYPE_MEITU:
		msg.title = context.getString(R.string.share_title_meitu);
		msg.description = mJoke.getTitle();
		thumb = BitmapUtil.getThumbBitmapFromCache(mJoke.getImgUrl(), 100, 100);
		break;
	}
	msg.thumbData = ImgUtil.bmpToByteArray(thumb, true);
	
	SendMessageToWX.Req req = new SendMessageToWX.Req();
	req.transaction = buildTransaction("webpage");
	req.message = msg;
	req.scene = scene;
	api.sendReq(req);
	thumb.recycle();
}
 
Example #13
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 5 votes vote down vote up
private void sendMessage(int platform, WXMediaMessage message, String transaction) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = transaction;
    req.message = message;
    req.scene = platform == SharePlatform.WX_TIMELINE ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;
    mIWXAPI.sendReq(req);
}
 
Example #14
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 #15
Source File: WeixinShareApi.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
private static void doShareWebPage(final String url,final String title,final String desc,final String img,final boolean timelined) {
    if(api==null) {
        api= WXAPIFactory.createWXAPI(MainApp.getContext(), APP_ID);
    }

    Bitmap bitmap= ImageUtil.getBitmap(img);
    Bitmap thumb =null;
    if(bitmap!=null){
        thumb=Bitmap.createScaledBitmap(bitmap, 64, 64, true);
    }

    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = url;
    WXMediaMessage msg = new WXMediaMessage(webpage);
    msg.title = title;
    msg.description = desc;

    if(thumb!=null) {
        msg.thumbData = BitmapUtil.bmpToByteArray(thumb, true);
    }else{
        Bitmap thumbIcon = BitmapFactory.decodeResource(MainApp.getInstance().getResources(), R.drawable.icon);
        msg.thumbData = BitmapUtil.bmpToByteArray(thumbIcon, true);
    }

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("webpage");
    req.message = msg;
    req.scene = timelined ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    api.sendReq(req);
}
 
Example #16
Source File: ShareByWeixin.java    From ShareSDK with MIT License 4 votes vote down vote up
public void shareImg(Bitmap bitmap, OnShareListener listener) {
    if (null == bitmap) {
        if (null != listener) {
            listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
        }
        return;
    }
    if (api.isWXAppInstalled()) {
        if (api.isWXAppSupportAPI()) {
            WXMediaMessage wxMediaMessage = new WXMediaMessage();
            wxMediaMessage.mediaObject = new WXImageObject(bitmap);

            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            while (width * height > THUMB_SIZE * THUMB_SIZE) {
                width /= 2;
                height /= 2;
            }
            Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap, width, height, true);
            try {
                ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
                thumbBmp.compress(Bitmap.CompressFormat.JPEG, 85, localByteArrayOutputStream);
                wxMediaMessage.thumbData = localByteArrayOutputStream.toByteArray();
                localByteArrayOutputStream.close();
            } catch (Exception e) {

            }

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = String.valueOf(System.currentTimeMillis());
            req.message = wxMediaMessage;
            if (ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND == channel) {
                req.scene = SendMessageToWX.Req.WXSceneSession;
            } else if (ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE == channel) {
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
            }
            api.sendReq(req);
        }
    } else {
        if (null != listener) {
            listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
        }
        ToastUtil.showToast(context, R.string.share_no_weixin_client, true);
    }
}
 
Example #17
Source File: ShareFragment.java    From Sky31Radio with Apache License 2.0 4 votes vote down vote up
private void sendRequestToWX(final int scene){
    picasso.load(sharingProgram.getThumbnail())
            .into(new Target() {
                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    byte[] data = BitmapUtils.encodeToByteArray(bitmap);
                    this.sendRequest(data);
                }

                @Override
                public void onBitmapFailed(Drawable errorDrawable) {
                    this.sendRequest(null);
                }

                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {

                }
                private void sendRequest(byte[] thumbData){
                    IWXAPI iwxapi = WXAPIFactory.createWXAPI(getActivity(), BuildConfig.WECHAT_APP_ID, true);
                    iwxapi.registerApp(BuildConfig.WECHAT_APP_ID);

                    WXMusicObject object = new WXMusicObject();
                    object.musicUrl = BuildConfig.APP_DOWNLOAD_URL;
                    object.musicDataUrl = sharingProgram.getAudio().getSrc();
                    object.musicLowBandUrl = sharingProgram.getThumbnail();
                    object.musicLowBandDataUrl = sharingProgram.getThumbnail();
                    WXMediaMessage message = new WXMediaMessage();
                    message.mediaObject = object;
                    message.title = sharingProgram.getTitle();
                    message.description = getString(R.string.tpl_wx_share_description,
                            getString(R.string.app_name),
                            sharingProgram.getAuthor());
                    message.thumbData  = thumbData;

                    SendMessageToWX.Req request = new SendMessageToWX.Req();
                    request.message = message;
                    request.transaction = String.valueOf(System.currentTimeMillis());
                    request.scene = scene;

                    iwxapi.sendReq(request);
                    iwxapi.unregisterApp();
                }
            });

}
 
Example #18
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 #19
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 #20
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 #21
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 #22
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 4 votes vote down vote up
@Override
public void shareImage(final int platform, final ShareImageObject shareImageObject,
        final Activity activity, final ShareListener listener) {
    Observable.fromEmitter(new Action1<Emitter<Pair<Bitmap, byte[]>>>() {
        @Override
        public void call(Emitter<Pair<Bitmap, byte[]>> emitter) {
            try {
                String imagePath = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(Pair.create(BitmapFactory.decodeFile(imagePath),
                        ImageDecoder.compress2Byte(imagePath, TARGET_SIZE, THUMB_SIZE)));
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, Emitter.BackpressureMode.BUFFER)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnRequest(new Action1<Long>() {
                @Override
                public void call(Long aLong) {
                    listener.shareRequest();
                }
            })
            .subscribe(new Action1<Pair<Bitmap, byte[]>>() {
                @Override
                public void call(Pair<Bitmap, byte[]> pair) {
                    WXImageObject imageObject = new WXImageObject(pair.first);

                    WXMediaMessage message = new WXMediaMessage();
                    message.mediaObject = imageObject;
                    message.thumbData = pair.second;

                    sendMessage(platform, message, buildTransaction("image"));
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    activity.finish();
                    listener.shareFailure(new Exception(throwable));
                }
            });
}
 
Example #23
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 4 votes vote down vote up
@Override
public void shareMedia(
        final int platform, final String title, final String targetUrl, final String summary,
        final ShareImageObject shareImageObject, final Activity activity, final ShareListener listener) {
    Observable.fromEmitter(new Action1<Emitter<byte[]>>() {

        @Override
        public void call(Emitter<byte[]> emitter) {
            try {
                String imagePath = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(ImageDecoder.compress2Byte(imagePath, TARGET_SIZE, THUMB_SIZE));
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, Emitter.BackpressureMode.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnRequest(new Action1<Long>() {
                @Override
                public void call(Long aLong) {
                    listener.shareRequest();
                }
            })
            .subscribe(new Action1<byte[]>() {
                @Override
                public void call(byte[] bytes) {
                    WXWebpageObject webpageObject = new WXWebpageObject();
                    webpageObject.webpageUrl = targetUrl;

                    WXMediaMessage message = new WXMediaMessage(webpageObject);
                    message.title = title;
                    message.description = summary;
                    message.thumbData = bytes;

                    sendMessage(platform, message, buildTransaction("webPage"));
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    activity.finish();
                    listener.shareFailure(new Exception(throwable));
                }
            });
}