首页 > 解决方案 > 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());

        }
    }

标签: javaandroid

解决方案


推荐阅读