Android微信分享 分享给朋友 缩略图移动端不显示 但是pc端、朋友圈却正常?
微信版本 7.0.10 手机小米 9
GlideUtils.getUrlBitmap(context, imgUrl, new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
//初始化一个WXWebpageObject,填写url
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
//用 WXTextObject 对象初始化一个 WXMediaMessage 对象
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.description = description;
msg.title = title;
// Bitmap urlBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
// bmpToByteArray1(urlBitmap, true);
// msg.setThumbImage(urlBitmap);
// urlBitmap.recycle();
msg.thumbData = bmpToByteArray(resource, 32);
LogUtils.d("msg.thumbData" + Arrays.toString(msg.thumbData));
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage"); //transaction字段用与唯一标示一个请求
req.message = msg;
req.scene = scene;
//调用api接口,发送数据到微信
wxApi.sendReq(req);
}
});
public static byte[] bmpToByteArray(Bitmap bmp, int imgSize) {
int quality = 95;
while (true) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, quality, baos);
byte[] bytes1 = baos.toByteArray();
LogUtil.d("aaaaa" + (bytes1.length / 1024));
if (bytes1.length / 1024 <= imgSize) {
return bytes1;
} else {
quality = quality - 5;
}
}
}