//
implementation "com.github.yuzhiqiang1993:zxing:2.1.8"
< H2 > Button triggers < / H2 >
@OnClick(R.id.imageButtonScan)
public void openScanCode(View view) {
AndPermission.with(this).runtime()
.permission(Permission.CAMERA, Permission.READ_EXTERNAL_STORAGE)
.onGranted(new Action<List<String>>() {
@Override
public void onAction(List<String> data) {
Intent intent = new Intent();
intent.setClass(getActivity(), CaptureActivity.class);
ZxingConfig config = new ZxingConfig();
config.setPlayBeep(true);//
config.setShake(true);// true
config.setDecodeBarCode(true);// true
config.setFullScreenScan(false);// true false
intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
startActivityForResult(intent, REQUEST_CODE_SCAN);
}
})
.onDenied(new Action<List<String>>() {
@Override
public void onAction(List<String> data) {
Uri packageURI = Uri.parse("package:" + getActivity().getPackageName());
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Toast.makeText(getActivity(), R.string.tips_no_camera_permission, Toast.LENGTH_SHORT).show();
}
}).start();
}
< H2 > callback method after successful scan < / H2 >
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// /
if (requestCode == REQUEST_CODE_SCAN && resultCode == getActivity().RESULT_OK) {
if (data != null) {
String content = data.getStringExtra(Constant.CODED_CONTENT);
if (content.length() == 12) {
//
checkInventoryCode(content);
} else {
//
checkContainer(content);
}
showDistributeMaterialList();
}
}
}
< H2 > phenomenon < / H2 >
after clicking the button, it crashes directly and reports the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.weihong.mes, PID: 6267
java.lang.RuntimeException: Parcel: unable to marshal value com.weihong.mes.model.distributeMaterial.GetNeedDistributeTable$DataBean@421dcce8
at android.os.Parcel.writeValue(Parcel.java:1273)
at android.os.Parcel.writeList(Parcel.java:660)
at android.os.Parcel.writeValue(Parcel.java:1233)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.FragmentState.writeToParcel(Fragment.java:132)
at android.os.Parcel.writeTypedArray(Parcel.java:1140)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:373)
at android.os.Parcel.writeParcelable(Parcel.java:1292)
at android.os.Parcel.writeValue(Parcel.java:1211)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
at android.os.Bundle.writeToParcel(Bundle.java:1692)
at android.os.Parcel.writeBundle(Parcel.java:643)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2594)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3318)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5334)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
< H2 > my guess < / H2 >
is in the button trigger code:
intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
startActivityForResult(intent, REQUEST_CODE_SCAN);
the value passing error in the above two lines of code, but I"m not sure. I added try-catch, to the button trigger method but still couldn"t catch the error message.
< H2 > other information < / H2 > this code is fine for me to use on the first-level page, and a personal test is available. The page on which the
error is reported is a secondary page. When the first-level page jumps to the second-level page, it transmits some information through Intent, which is accepted in the second-level page as follows:
orderId = getArguments().getString("orderId");
getNeedDistributeTableDataBeanList = (List<GetNeedDistributeTable.DataBean>) getArguments().getSerializable("getNeedDistributeTableDataBeanList");
so open the QR code scan page in the second-level page, and the QR code scan page is equivalent to a third-level page.
I don"t know if this other information is useful, so just write it down for the time being.