原先集成过微信的分享,分享到朋友圈和微信对话都没有问题。
项目上线由于图片各异,最近会偶尔出现分享到朋友圈时候根本就打不开share的界面,但是到微信聊天是可以;
下面贴出先前的代码:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.send_img);
WXImageObject imgObj = new WXImageObject(bmp);
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
bmp.recycle();
msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction(“img”);
req.message = msg;
req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
很多人说是缩略图的大小的问题,但是在将缩略图改成很小之后还是没有成效。最后换成下面微信sdk提供的一种方式:
WXImageObjectimgObj=newWXImageObject();
imgObj.setImagePath(mCurrentUrl);
WXMediaMessage msg=newWXMediaMessage();
msg.mediaObject=imgObj;
Bitmap bmp=BitmapFactory.decodeFile(mCurrentUrl);
Bitmap thumbBmp=Bitmap.createScaledBitmap(bmp,THUMB_SIZE,THUMB_SIZE,true);
// bmp.recycle();
msg.thumbData=bmpToByteArray(thumbBmp,true);// 设置缩略图
SendMessageToWX.Req req=newSendMessageToWX.Req();
req.transaction=buildTransaction(“img”);
req.message=msg;
req.scene= isTimelineCb ?SendMessageToWX.Req.WXSceneTimeline:SendMessageToWX.Req.WXSceneSession;
booleanflag=mWXAPIFactory.sendReq(req);