2

i am trying to make an application that will work on the phone to scan bar code. so i have tried the code bellow but it gives me this error

11-28 11:18:45.750: E/AndroidRuntime(772): FATAL EXCEPTION: main
11-28 11:18:45.750: E/AndroidRuntime(772): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
11-28 11:18:45.750: E/AndroidRuntime(772):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)

i am still trying this using emulator and external camera on my laptop. so can you please help me

here is the code:

public class MainActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        HandleClick hc = new HandleClick();
        findViewById(R.id.butQR).setOnClickListener(hc);
        findViewById(R.id.butProd).setOnClickListener(hc);
        findViewById(R.id.butOther).setOnClickListener(hc);
      }
      private class HandleClick implements OnClickListener{
        public void onClick(View arg0) {

            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
          switch(arg0.getId()){
            case R.id.butQR:
              intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            break;
            case R.id.butProd:
              intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
            break;
            case R.id.butOther:
              intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR");
            break;
          }
          startActivityForResult(intent, 0);    //Barcode Scanner to scan for us
        }
      }
      public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
          TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
          TextView tvResult=(TextView)findViewById(R.id.tvResult);
          if (resultCode == RESULT_OK) {
            tvStatus.setText(intent.getStringExtra("SCAN_RESULT_FORMAT"));
            tvResult.setText(intent.getStringExtra("SCAN_RESULT"));
          } else if (resultCode == RESULT_CANCELED) {
            tvStatus.setText("Press a button to start a scan.");
            tvResult.setText("Scan cancelled.");
          }
        }
      }
    }

Here is Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sdk.example.test"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
        >
        <activity
            android:name="sdk.example.test.MainActivity"
            android:label="@string/app_name" >


            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
CoT
  • 157
  • 2
  • 13

2 Answers2

0

The app to read bar code is not installed on you phone first install this app first.

click here

Ali Imran
  • 8,927
  • 3
  • 39
  • 50
  • It is also possible to just include the Zxing barcode.jar in the application, then you dont need to prompt your users to download the scanner app – Flexo Nov 29 '12 at 09:02
  • @Flexo it is not a recommend way! – Mohsin Naeem Nov 29 '12 at 09:05
  • It might not be the recommended way, but if his project wants to go that way because it makes sense for them they should also know that it is an option. – Flexo Nov 29 '12 at 09:06
  • @Flexo is it possible to install the app on my laptop to be able to test it before installing it on phone? – CoT Nov 29 '12 at 09:20
  • @Flexo you may be intall this app on [Bluestack](http://bluestacks.com/) application if your laptop has camera :) – Ali Imran Nov 29 '12 at 09:36
0

you need use ScanningViaIntent it handles all the things. Very well :)

Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53