上个项目做Android的微信分享,需要分享的内容有图片有文字,看了微信分享的SDK,貌似没有这个API,在网上搜了好久,总算找到解决方法了,直接上代码:
1 public void sendReq(Context context, String title, String content, 2 Bitmap bmp, boolean isLine) { 3 String url = BASE_URL;// 收到分享的好友点击信息会跳转到这个地址去,并且这个是必须要的 4 WXWebpageObject Object = new WXWebpageObject(); 5 Object.webpageUrl = url; 6 WXMediaMessage message = new WXMediaMessage(Object); 7 message.title = title;// 不能太长,否则微信会提示出错。不过博主没验证过具体能输入多长。 8 message.description = content; 9 message.thumbData = Util.bmpToByteArray(bmp, true); 10 SendMessageToWX.Req req = new SendMessageToWX.Req(); 11 req.transaction = buildTransaction("img/text"); 12 req.message = message; 13 req.scene = isLine ? SendMessageToWX.Req.WXSceneTimeline 14 : SendMessageToWX.Req.WXSceneSession; 15 api.sendReq(req); 16 }