The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process.
Consequently this exception can be thrown when there are many transactions in progress even when most of the individual transactions are of moderate size.
你好,麻烦再重现一次,在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,提供一下微信号,复现问题的详细时间点(如:2020-4-10 10:10)
先说结论:
1,小于1M 的图理论上可以发出去,建议限制在750K以内,保证图的清晰度。因Binder 上限是1M,缩略图的上限是128K 。
2,使用这个接口可控性更好。public WXImageObject(byte[] bitmap)。理由是其它接口会有再处理,不便判断。
原因:
1,图的大小限制
a,系统限制。图要在你的app 和 微信间传。所以要看系统限制1M。参考如下
https://developer.android.com/reference/android/os/TransactionTooLargeException
The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process.
Consequently this exception can be thrown when there are many transactions in progress even when most of the individual transactions are of moderate size.
b,微信限制,这个得看反编代码。(注代码明显不是一个人写得各处限制不一样,我们只看重点)
先说推理: 缩略图限制128K,系统限制1M。所以大图限制750K,给其它数据留点空间。
缩略图限制128K。看WXMediaMessage反编代码
final boolean checkArgs() {
if (this.getType() != 8 || this.thumbData != null && this.thumbData.length != 0) {
if (d.a(this.getType()) && (this.thumbData == null || this.thumbData.length > 131072)) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, thumbData should not be null or exceed 128kb");
return false;
} else if (!d.a(this.getType()) && this.thumbData != null && this.thumbData.length > 65536) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, thumbData is invalid");
return false;
} else if (this.title != null && this.title.length() > 512) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, title is invalid");
return false;
} else if (this.description != null && this.description.length() > 1024) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, description is invalid");
return false;
} else if (this.mediaObject == null) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, mediaObject is null");
return false;
} else if (this.mediaTagName != null && this.mediaTagName.length() > 64) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, mediaTagName is too long");
return false;
} else if (this.messageAction != null && this.messageAction.length() > 2048) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, messageAction is too long");
return false;
} else if (this.messageExt != null && this.messageExt.length() > 2048) {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, messageExt is too long");
return false;
} else {
return this.mediaObject.checkArgs();
}
} else {
Log.e("MicroMsg.SDK.WXMediaMessage", "checkArgs fail, thumbData should not be null when send emoji");
return false;
}
}
2,直接传位图,微信会再处理,所以传图的二进制更好。且压缩用JPG的方式。
看证据:看WXImageObject反编代码。微信有再压缩。
public WXImageObject(Bitmap var1) {
try {
ByteArrayOutputStream var2 = new ByteArrayOutputStream();
var1.compress(CompressFormat.JPEG, 85, var2);
this.imageData = var2.toByteArray();
var2.close();
} catch (Exception var3) {
Log.e("MicroMsg.SDK.WXImageObject", "WXImageObject <init>, exception:" + var3.getMessage());
}
}