|
...
|
...
|
@@ -3,6 +3,7 @@ package com.theweflex.react; |
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
|
...
|
...
|
@@ -46,6 +47,7 @@ import com.tencent.mm.opensdk.openapi.IWXAPI; |
|
|
|
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
|
|
|
|
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
...
|
...
|
@@ -60,6 +62,46 @@ public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEv |
|
|
|
private final static String INVOKE_FAILED = "WeChat API invoke returns false.";
|
|
|
|
private final static String INVALID_ARGUMENT = "invalid argument.";
|
|
|
|
|
|
|
|
|
|
|
|
// 缩略图大小 kb
|
|
|
|
private final static int THUMB_SIZE = 32;
|
|
|
|
|
|
|
|
private static byte[] bitmapTopBytes(Bitmap bitmap) {
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
|
|
|
|
bitmap.recycle();
|
|
|
|
return baos.toByteArray();
|
|
|
|
}
|
|
|
|
private static byte[] bitmapResizeGetBytes(Bitmap image, int size) {
|
|
|
|
// little-snow-fox 2019.10.20
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
// 质量压缩方法,这里100表示第一次不压缩,把压缩后的数据缓存到 baos
|
|
|
|
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
|
|
|
|
int options = 100;
|
|
|
|
|
|
|
|
|
|
|
|
// 循环判断压缩后依然大于 32kb 则继续压缩
|
|
|
|
while (baos.toByteArray().length / 1024 > size) {
|
|
|
|
// 重置baos即清空baos
|
|
|
|
baos.reset();
|
|
|
|
if (options > 10) {
|
|
|
|
options -= 8;
|
|
|
|
} else {
|
|
|
|
return bitmapResizeGetBytes(Bitmap.createScaledBitmap(image, 280, image.getHeight() / image.getWidth() * 280, true), size);
|
|
|
|
}
|
|
|
|
// 这里压缩options%,把压缩后的数据存放到baos中
|
|
|
|
image.compress(Bitmap.CompressFormat.JPEG, options, baos);
|
|
|
|
}
|
|
|
|
return baos.toByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Bitmap Bytes2Bimap(byte[] b) {
|
|
|
|
if (b.length != 0) {
|
|
|
|
return BitmapFactory.decodeByteArray(b, 0, b.length);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public WeChatModule(ReactApplicationContext context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
...
|
...
|
@@ -425,6 +467,7 @@ public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEv |
|
|
|
message.mediaObject = mediaObject;
|
|
|
|
|
|
|
|
if (thumbImage != null) {
|
|
|
|
thumbImage=Bytes2Bimap(bitmapResizeGetBytes(thumbImage, THUMB_SIZE));
|
|
|
|
message.setThumbImage(thumbImage);
|
|
|
|
}
|
|
|
|
if (data.hasKey("title")) {
|
...
|
...
|
|