我是安卓新手。我正在开发一个应用程序,我必须使用 zxing 来扫描条形码和二维码。在我的应用程序中,我不能使用第三方软件。这意味着我不能在我的应用程序中使用这些代码行
IntentIntegrator integrator = new IntentIntegrator(shopping.this);
integrator.initiateScan();
所以,在那种情况下,我在阅读了几个教程后使用了这些行代码。
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
// intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
startActivityForResult(intent, 0);
但不幸的是,这对我来说是例外,我的总 log-cat 输出如下 -
01-06 06:00:02.131: D/AndroidRuntime(956): Shutting down VM
01-06 06:00:02.131: W/dalvikvm(956): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-06 06:00:02.161: E/AndroidRuntime(956): FATAL EXCEPTION: main
01-06 06:00:02.161: E/AndroidRuntime(956): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }
01-06 06:00:02.161: E/AndroidRuntime(956): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.app.Activity.startActivityForResult(Activity.java:3351)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.app.Activity.startActivityForResult(Activity.java:3312)
01-06 06:00:02.161: E/AndroidRuntime(956): at com.google.zxing.shopping.shopping$1.onClick(shopping.java:99)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.view.View.performClick(View.java:4084)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.view.View$PerformClick.run(View.java:16966)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.os.Handler.handleCallback(Handler.java:615)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.os.Handler.dispatchMessage(Handler.java:92)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.os.Looper.loop(Looper.java:137)
01-06 06:00:02.161: E/AndroidRuntime(956): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-06 06:00:02.161: E/AndroidRuntime(956): at java.lang.reflect.Method.invokeNative(Native Method)
01-06 06:00:02.161: E/AndroidRuntime(956): at java.lang.reflect.Method.invoke(Method.java:511)
01-06 06:00:02.161: E/AndroidRuntime(956): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-06 06:00:02.161: E/AndroidRuntime(956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-06 06:00:02.161: E/AndroidRuntime(956): at dalvik.system.NativeStart.main(Native Method)
但是当我只是替换这条线
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
到这条线
Intent intent = new Intent(shopping.this, CaptureActivity.class);
我运行我的应用程序,它为我成功运行,但问题是它只扫描 **QR 码,它不适用于 BAR 码。为了方便那些想要帮助的人,我将展示我的清单文件
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyrad.xybuy"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.flash"
android:required="false" />
<uses-feature android:name="android.hardware.screen.landscape" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:hardwareAccelerated="true"
android:icon="@drawable/logo_xybuy"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<activity
android:name=".RegisterCustomer"
android:label="@string/title_activity_register_customer" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- BarCodeScanner -->
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:stateNotNeeded="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" ><intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
<!-- Allow web apps to launch Barcode Scanner by linking to http://zxing.appspot.com/scan. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="zxing.appspot.com"
android:path="/scan"
android:scheme="http" />
</intent-filter>
<!-- We also support a Google Product Search URL. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.google.com"
android:path="/m/products/scan"
android:scheme="http" />
</intent-filter>
<!-- And the UK version. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.google.co.uk"
android:path="/m/products/scan"
android:scheme="http" />
</intent-filter>
<!-- Support zxing://scan/?... like iPhone app -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="scan"
android:path="/"
android:scheme="zxing" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.PreferencesActivity"
android:label="@string/preferences_name"
android:stateNotNeeded="true" >
</activity>
<activity
android:name="com.google.zxing.client.android.encode.EncodeActivity"
android:label="@string/share_name"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="com.google.zxing.client.android.ENCODE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- This allows us to handle the Share button in Contacts. -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/x-vcard" />
</intent-filter>
<!-- This allows us to handle sharing any plain text . -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.history.HistoryActivity"
android:label="@string/history_title"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="WelcomeCustomerSplash" >
</activity>
<activity android:name="HomePage" >
</activity>
<activity android:name=".buy.BuyClick" >
</activity>
<activity android:name=".shoppinglistmanage.ShoppingListManageCompulsory" >
</activity>
<activity android:name=".otw.OtwClick" >
</activity>
<activity android:name=".buy.ClickIHaveList" >
</activity>
<activity android:name=".buy.WaitToPopulateData" >
</activity>
<activity android:name=".buy.ListWithDiscountNetPrice" >
</activity>
<activity android:name=".buy.PaymentOption" >
</activity>
<activity android:name=".buy.PurchaseItemList" >
</activity>
<activity android:name=".buy.UnPurchaseItemList" >
</activity>
<activity android:name=".googlemap.LocateForNearestStore" >
</activity>
<activity android:name=".googlemap.WhereIam" >
</activity>
<activity android:name=".paymentgateway.ShoppingPaymentGatewayPayPalActivity" >
</activity>
<activity
android:name="com.paypal.android.MEP.PayPalActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>
<activity
android:name="com.google.zxing.shopping.PurchaseList"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity android:name="com.google.zxing.shopping.DeviceListActivity" >
</activity>
<activity android:name="com.google.zxing.shopping.shopping" >
</activity>
<!-- purchase -->
<!-- DeviceList -->
<activity android:name="com.google.zxing.shopping.DataLayer" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.payment.BillingAddress" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.cart.ListCart" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.category.ListCategory" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.subcategory.ListCategorySubCategory" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.subcategory.TabSubCategory" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.catalog.ListCatalog" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.checkout.ListCheckOut" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.item.ItemDetails" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.item.ListItem" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.item.ItemReview" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.merchant.ListMerchant" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.merchant.TabMerchant" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.payment.ModeOfPayment" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.offer.ListOffer" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.payment.Payment" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.category.TabCategry" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.item.TabItem" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.item.TabItemDetails" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.item.TabItemDetailsAndReview" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.deparment.ListDepartment" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.catalog.TabCatalog" >
</activity>
<activity android:name="com.xyrad.xybuy.ecommerce.subcategory.TabSubCategoryegory.TabSubCategoryegory.TabSubCategory" >
</activity>
</application>
<!-- Category -->
所以,这是我对我的问题的描述。所以请有人帮助我。我真的会从心底里感谢所有人。提前感谢所有人。