user3345767 user3345767 - 8 months ago 38
Android Question

Barcode scanning doesn't work if device doesn't have barcode reader app installed

i try to create barcode reader i used Zxing library and i have a problem
divice witch has own barcode reader - my app working perfect but divice witch has not barcode reader app my app does not working
this is a my code
how i can check if divice has barcode reader?

public class MainActivity extends Activity {
TextView tvStatus;
TextView tvResult;
private static String BarCodeResult;

protected void onCreate(Bundle savedInstanceState) {

tvStatus = (TextView) findViewById(;
tvResult = (TextView) findViewById(;
BarCodeResult = tvResult.getText().toString();

Button scanBtn = (Button) findViewById(;

scanBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

try {

Intent intent = new Intent(
startActivityForResult(intent, 0);

} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "ERROR:" + e, 1)




public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {

Intent in = new Intent(getApplicationContext(), Result.class);
in.putExtra("KEY_BarCodeResult", intent.getStringExtra("SCAN_RESULT"));

} else if (resultCode == RESULT_CANCELED) {
tvStatus.setText("Press a button to start a scan.");
tvResult.setText("Scan cancelled.");


You aren't handling the case where the app is not installed, yes, and there is nothing available to handle the Intent.

Just use the IntentIntegrator class from the project in your app, which handles this:

Or you can see what it does and do something similar with ActivityNotFoundException.