1
I’m trying to add barcode reading functionality to my app through com.google.zxing.client.android.SCAN.
I added the calls to the application via Intent according to the code below:
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.codigodebarras, container, false);
}
@Override
public void onStart() {
String aux;
super.onStart();
UpdateView();
}
private void UpdateView() {
scanQR = (Button) getActivity().findViewById(R.id.scanQR);
scanQR.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try {
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
CustomDialogSimNao cdsn = new CustomDialogSimNao(getActivity(), "Nenhum scanner foi encontrado. Deseja fazer o download?");
cdsn.show();
}
}
});
scanCode = (Button) getActivity().findViewById(R.id.scanCodBar);
scanCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try {
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
CustomDialogSimNao cdsn = new CustomDialogSimNao(getActivity(), "Nenhum scanner foi encontrado. Deseja fazer o download?");
cdsn.show();
}
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == getActivity().RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Toast toast = Toast.makeText(getActivity(), "Content:" + contents + " Format:" + format, Toast.LENGTH_LONG);
toast.show();
}
}
}
The application is called normally and the result goes back to my application as it should be, but there are two problems and I would like if possible help me in these issues.
When running the application it usually recognizes the barcodes very quickly, but when it is called via Intent by my application it has a lot of difficulty to read the same barcodes.
I cannot locate the number in the results returned to my application.
How to make the call correctly so it can recognize the codes quickly? Where I find the barcode code in the returned information?
Grateful.