标签:stat scene get disk tor edr bmp _id map
private String APP_ID = "00000000000000000"; //微信 APPID private IWXAPI iwxapi;
private void regToWx() { iwxapi = WXAPIFactory.createWXAPI(context, APP_ID, true);//这里context记得初始化 iwxapi.registerApp(APP_ID); }
IMServer.getDiskBitmap(IMServer.url);
这个是我写的 一个从内存卡读取照片的类.. 可根据自己需求更改
private void wxShare() { Bitmap bp = IMServer.getDiskBitmap(IMServer.url); WXImageObject wxImageObject = new WXImageObject(bp); WXMediaMessage msg = new WXMediaMessage(); msg.mediaObject = wxImageObject; //设置缩略图 Bitmap mBp = Bitmap.createScaledBitmap(bp, 120, 120, true); bp.recycle(); msg.thumbData = bmpToByteArray(mBp, true); SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = buildTransaction("img");// transaction字段用 req.message = msg; req.scene = SendMessageToWX.Req.WXSceneSession; iwxapi.sendReq(req); }
我先上代码,我们看看上面的代码..设置缩略图那
官方给的 代码是
msg.thumbData = Util.bmpToByteArray(thumbBitmap, true);
然后Util类,居然找不到(我用了qq的jar包,只能在这里找到.....)
所以我只能去demo里面找,然后把bmpToByteArray方法提取出来,如下
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) { ByteArrayOutputStream output = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, output); if (needRecycle) { bmp.recycle(); } byte[] result = output.toByteArray(); try { output.close(); } catch (Exception e) { e.printStackTrace(); } return result; }
然后再往下看,
req.transaction = buildTransaction("img");// transaction字段用
很明显 后面的是一个方法, 官方也没给出... 老方法 ,去demo里面找,如下
private String buildTransaction(final String type) { return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis(); }
标签:stat scene get disk tor edr bmp _id map
原文地址:http://www.cnblogs.com/zhujiabin/p/7872318.html