Java Code Examples for com.tencent.mm.sdk.modelmsg.SendMessageToWX#Req
The following examples show how to use
com.tencent.mm.sdk.modelmsg.SendMessageToWX#Req .
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: UserInfoActivity.java From WeGit with Apache License 2.0 | 6 votes |
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 2
Source File: WeixinHelper.java From android-common-utils with Apache License 2.0 | 6 votes |
/** * 分享文本 * @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: WeixinHelper.java From android-common-utils with Apache License 2.0 | 6 votes |
/*** * @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 4
Source File: WeixinHelper.java From android-common-utils with Apache License 2.0 | 6 votes |
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: WeixinShareApi.java From browser with GNU General Public License v2.0 | 5 votes |
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 6
Source File: WeChatHelper.java From talk-android with MIT License | 5 votes |
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 7
Source File: WxShareInstance.java From ShareUtil with Apache License 2.0 | 5 votes |
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 8
Source File: ShareByWeixin.java From ShareSDK with MIT License | 5 votes |
private void send(Bitmap bitmap) { SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = String.valueOf(System.currentTimeMillis()); req.message = buildWXMediaMessage(bitmap); if (channel == ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND) { req.scene = SendMessageToWX.Req.WXSceneSession; } else if (channel == ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE) { req.scene = SendMessageToWX.Req.WXSceneTimeline; } api.sendReq(req); }
Example 9
Source File: SharePopWindow.java From QiQuYing with Apache License 2.0 | 5 votes |
/** * 分享到微信朋友或者朋友圈 * @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 10
Source File: WeixinHelper.java From android-common-utils with Apache License 2.0 | 5 votes |
@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 11
Source File: WeixinHelper.java From android-common-utils with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(SendMessageToWX.Req req) { if(req.message == null){ Object cl = mCallbackMap.get(req.transaction.hashCode()); if(cl!=null){ ((IWXShareCallback)cl).onShareFailed("read image to WXMediaMessage.thumbData failed"); mCallbackMap.clear(); } }else{ mWxApi.sendReq(req); } super.onPostExecute(req); }
Example 12
Source File: Activity_Result.java From MortgageCalculator with Apache License 2.0 | 4 votes |
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 13
Source File: Activity_Result_Combination.java From MortgageCalculator with Apache License 2.0 | 4 votes |
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 14
Source File: Activity_Result.java From MortgageCalculator with Apache License 2.0 | 4 votes |
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 15
Source File: Activity_Result_Combination.java From MortgageCalculator with Apache License 2.0 | 4 votes |
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 16
Source File: ShareByWeixin.java From ShareSDK with MIT License | 4 votes |
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); } }