当我通过回收查看项捕获图像时,我得到了此提示,但是当我捕获照片时,代码对于第一项和第二项都工作正常,
E / JavaBinder:!!!绑定交易失败!!! (包裹大小= 1058220)E / Android运行时:致命异常:主要 流程:com.xtremesolutions.vehicleinspection,PID:8139 java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小1058220 个字节 在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) 在android.app.ActivityThread.main(ActivityThread.java:6523) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:942) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) 造成原因:android.os.TransactionTooLargeException:数据包大小1058220字节 在android.os.BinderProxy.transactNative(本地方法) 在android.os.BinderProxy.transact(Binder.java:617) 在android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3632) 在android.app.ActivityThread $ StopInfo.run(ActivityThread.java:3974) 在android.os.Handler.handleCallback(Handler.java:761) 在android.os.Handler.dispatchMessage(Handler.java:98) 在android.os.Looper.loop(Looper.java:156) 在android.app.ActivityThread.main(ActivityThread.java:6523) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:942) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
代码: 该代码位于Viewholder中
@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());
}
}