I am new to android can someone help me please, following is the code i tried to run for scanning the barcode but it gives an error whenever i click the button it says force to close what should i do help me please.
this.btnCheck = (Button) findViewById(R.id.btnsearch);
this.btnCheck.setOnClickListener(
new OnClickListener() {
public void onClick(View v)
{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
}
);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT");
Toast.makeText(this, "the scaned code is = "+ contents, Toast.LENGTH_SHORT).show();
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
Edit Logcat:
this is the log cat now Starting:
Intent { act=com.google.zxing.client.android.SCAN (has extras) } from pid 359 thread exiting with uncaught exception (group=0x40015560)
08-18 01:52:00.995: ERROR/AndroidRuntime(359): FATAL EXCEPTION: main
08-18 01:52:00.995: ERROR/AndroidRuntime(359): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
08-18 01:52:00.995: ERROR/AndroidRuntime(359): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
This exception probably means that the device you are trying to use doesn’t have BarcodeScanner installed. You can use this code somewhere in your app to check, and prompt the user to install it form the market if they do not already have.
Edit: Change this line:
to this:
I highly suggest you go to this page Read it thoroughly, and then follow the two links that are underneath the code example and look at all of the code that it shows. Even if you do not understand it, it will give you some idea what is capable via Intents with the BarcodeScanner app.