I'm trying to add barcode functionality to my application 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 returns to my application as it should be, however two problems occur and I would like if possible to help me with these issues.
When I run the application it usually recognizes the barcodes very quickly, but when it is called via Intent by my application it has very difficult to read the same bar codes.
I can not find the number in the results returned for my application.
How to make the call correctly so that it can recognize codes quickly? Where do I find the barcode code in the information returned?
Thank you.