使用Zxing获取android.content.ActivityNotFoundException

时间:2012-01-24 12:25:33

标签: android android-activity barcode zxing

我遵循了以下教程:http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/

但即使在编辑了android manifest xml后,我也收到了以下错误:

 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }  

我的代码:

 public class BarCodeScannerActivity extends Activity {  
        /** Called when the activity is first created. */  
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  


        Button ok;  

       ok=(Button) findViewById(R.id.b1);  
       ok.setOnClickListener(new View.OnClickListener()  
         {

           public void onClick(View v) {   
              // TODO Auto-generated method stub 
              System.out.println("Helllllllloooooooo");
              Intent intent = new Intent("com.google.zxing.client.android.SCAN");  
            intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE","QR_CODE_MODE");       
                startActivityForResult(intent, 0);   

        }
    });
        }

     public void onActivityResult(int requestCode, int resultCode, Intent intent) {             
    System.out.println("onActivityResult________resultCode________ "+resultCode);   

    if (requestCode == 0) {   
        if (resultCode == RESULT_OK) {    
            String contents = intent.getStringExtra("SCAN_RESULT"); 
            System.out.println("contentsssssssssssssssssssssss" + contents);
            Toast.makeText(getApplicationContext(),"Congratulations!!!... Product Code"+ contents + "On Scanning This Item..." ,Toast.LENGTH_LONG).show();  

            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");   
            System.out.println("Formaattttttttttttttt " + format);
            // Handle successful scan      
        }   else if (resultCode == RESULT_CANCELED) {   
            // Handle cancel       
          }    
      } 
  }
  }

主要文件:

    

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".BarCodeScannerActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>



    </activity>


    <activity android:name="com.google.zxing.client.android.CaptureActivity"
    android:screenOrientation="landscape"
    android:configChanges="orientation|keyboardHidden"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:windowSoftInputMode="stateAlwaysHidden">

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


        <intent-filter>
            <action android:name="com.google.zxing.client.android.SCAN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>





</application>

<uses-permission android:name="android.permission.CAMERA" />

你好

现在我在更新我的清单时遇到一个奇怪的附加屏幕截图问题如下:

<activity android:name="com.google.zxing.client.android.CaptureActivity"  
              android:screenOrientation="landscape"  
              android:configChanges="orientation|keyboardHidden"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
             android:windowSoftInputMode="stateAlwaysHidden">
  <intent-filter>
    <action android:name="android.intent.action.MAIN"/>  
    <category android:name="android.intent.category.LAUNCHER"/>
  </intent-filter>
  <intent-filter>
    <action android:name="com.google.zxing.client.android.SCAN"/>
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
  </activity>
![enter image description here][1]
<activity android:name=".ScanItemActivity"
        android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:windowSoftInputMode="stateAlwaysHidden">
        </activity>

我的意思是说“对不起,Android相机遇到了问题。你可能需要 重启设备。“

logcat中没有任何内容。

1 个答案:

答案 0 :(得分:3)

这很困惑。如果要按Intent进行集成,则根本不需要更改清单,因此请删除仅为集成而更改的任何内容。

未安装该应用,您没有正确处理此问题。您必须抓住ActivityNotFoundException,或提前确定安装了处理Intent的应用。

但是,不需要任何这种复杂性。见http://code.google.com/p/zxing/wiki/ScanningViaIntent。您可以使用IntentIntegrator,它可以在几行代码中正确地完成所有这些工作。