java - java.lang.RuntimeException: android.os.TransactionTooLargeException: 数据包大小 1058220 字节
问题描述
当我通过回收视图项目捕获图像时,我得到了这个,但是代码对第一个项目和第二个项目工作正常,当我捕获照片时它会给出以下错误。
E/JavaBinder:!!!Binder 交易失败!!!(parcel size = 1058220) E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xtremesolutions.vehicleinspection, PID: 8139 java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1058220 bytes at android.app.ActivityThread$StopInfo .run(ActivityThread.java:3982) 在 android.os.Handler.handleCallback(Handler.java:761) 在 android.os.Handler.dispatchMessage(Handler.java:98) 在 android.os.Looper.loop(Looper. java:156) 在 com.android.internal.os 的 java.lang.reflect.Method.invoke(Native Method) 的 android.app.ActivityThread.main(ActivityThread.java:6523)。
代码: 此代码在视图中
@OnClick(R.id.btn_attach_picture) void onAttachPictureClicked(View view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
photoFile = getPhotoFileUri();
Uri fileProvider = FileProvider.getUriForFile(this.itemView.getContext(), BuildConfig.APPLICATION_ID+".provider", photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileProvider);
}
//intent.putExtra("questionId",item.getQuestionId());
QuestionAdapter.CURRENT = item.getQuestionId();
if (intent.resolveActivity(this.itemView.getContext().getPackageManager()) != null) {
//((Activity)this.itemView.getContext()).startActivityForResult(intent, CAMERA_REQUEST);
fragment.startActivityForResult(intent, CAMERA_REQUEST);
}
final int[] count = {0};
final Handler h =new Handler();
Runnable runnable =new Runnable() {
@Override
public void run() {
count[0]++;
if (count[0] < 50){
if (!item.getEvidence().equals("")){
attachPicture.setText("Picture Attached");
attachPicture.setTextColor(Color.parseColor("#d63031"));
}else{
h.postDelayed(this,500);
}
}
}
};
h.postDelayed(runnable,2000);
}
这段代码在片段中
public void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
photo = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
} else {
photo = (Bitmap) data.getExtras().get("data");
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 40, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String evidence = Base64.encodeToString(byteArray, Base64.DEFAULT);
int count = 0;
for (Question question:
this.questions) {
if (question.getQuestionId() == CURRENT){
question.setEvidence(evidence);
break;
}
count++;
}
}
} catch (Exception e) {
MessageHelper.showMessage("Error", e.getMessage(), fragment.getContext());
}
}
解决方案
推荐阅读
- c++ - 外部存储库的 bazel WORKSPACE 文件导致缺少#includes
- arrays - 仅当行包含特定值时才查找单元格数组的总和
- activemq - ActiveMQ 在控制台过滤多个日志行
- css - 如何在 Angular 7 应用程序中共享 LESS 或 CSS 文件?
- javascript - 将 e.location 字符串拆分为变量
- types - Ocaml 用户定义类型和函数
- python - 尝试使用 \t 执行多个选项卡
- javascript - 使用 Chrome 扩展程序更改选项时在选择元素上触发事件
- google-cloud-platform - Big Query - 阻止本地文件上传
- python - 将一系列 str 转换为日期