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>
有帮助吗?

解决方案

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

click here

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top