简体   繁体   English

zxing中的ActivityNotFoundException

[英]ActivityNotFoundException in zxing

I am new in android. 我是android新手。 I am developing a App in which i have to used zxing for scanning bar code and QR code. 我正在开发一个应用程序,其中必须使用zxing扫描条形码和QR码。 In my App i can not use third party software. 在我的应用程序中,我无法使用第三方软件。 That means i can't use these line of code in my App 这意味着我不能在我的应用程序中使用这些代码行

 IntentIntegrator integrator = new IntentIntegrator(shopping.this);
            integrator.initiateScan();

So, in that case i used these line code after reading several tutorial . 因此,在那种情况下,我在阅读了几本教程后使用了这些行代码。

    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); 

But unfortunately this is showing Exception for me, my total log-cat output is as follow- 不幸的是,这对我来说显示了异常,我的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)

But when i just replace this line 但是当我只替换这条线时

   Intent intent = new Intent("com.google.zxing.client.android.SCAN");

to this line 到这条线

   Intent intent = new Intent(shopping.this, CaptureActivity.class);

and i run my App it successfully run for me , but problem is that it is only scanning **QR Code , it not working for BAR code . 我运行了我的应用程序,它为我成功地运行了,但是问题是它只能扫描** QR Code,它不能用于BAR代码 For convenience for those who want to help i am going to show my Manifest file 为了方便那些想要帮助的人,我将显示我的清单文件

              <?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 -->

So, this my description of my problem. 因此,这就是我对问题的描述。 So please some one help me . 所以请有人帮我。 I will really thankful to all from my bottom of heart. 我将衷心感谢所有人。 thanks in advance to all. 在此先感谢所有人。

Do you have this 3rd party application installed in your phone or emulator where ever you are running the application? 您是否在运行该应用程序的手机或仿真器中安装了该第三方应用程序?

Android operating system couldn't find the activity. Android操作系统找不到活动。

          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) }

Use try and catch block, make sure the application is installed in your phone, if it's not : point the user to 3rd party application on playstore. 使用try and catch块,确保未在手机中安装该应用程序(如果未安装):将用户指向Playstore上的第三方应用程序。

使用提供的IntentIntegrator类,因为它将处理您需要处理的情况,例如未安装应用程序。

You are getting ActivityNotFoundException as Zxing application is not installed in your device. 您正在获取ActivityNotFoundException,因为您的设备中未安装Zxing应用程序。 So Please check whether it is installed or not. 因此,请检查是否已安装。 If it's not then redirect user to playstore-page of Zxing: 如果不是,则将用户重定向到Zxing的playstore-page:

I've implemented some code for these. 我已经为它们实现了一些代码。 Modify it according to your needs: 根据需要进行修改:

boolean isZxingInstalled;
/*
 *Checking whether Zxing is installed or not
 */ 
try
{
ApplicationInfo info = getPackageManager().getApplicationInfo("com.google.zxing.client.android", 0 );
boolean isZxingInstalled = true;
    }
catch(PackageManager.NameNotFoundException e){
                isZxingInstalled=false;
          }

/*
 * Store the boolean value on the basis of Zxing is installed or not
 */

if(isZxingInstalled) //If it is then intent Zxing application
 {
         //start the facebook app
         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); 
  }
 else //It's not then redirect user to PlayStore-ZxingPlage
  {
    /*
     *Checking whether PlayStore is installed in device or not?
     */
     boolean isPlayStoreInstalled
     try
     {
      ApplicationInfo i=getPackageManager().getApplicationInfo("com.google.vending", 0 );
      boolean isPlayStoreInstalled = true;
      }
     catch(PackageManager.NameNotFoundException e){
                isPlayStoreInstalled=false;
          }

      /*
       * If it is the download Zxing
       */ 
      if(isPlayStoreInstalled)
       {
        Intent DownloadZxing = new Intent(Intent.ACTION_VIEW,Uri.parse("market://detailsid=com.google.zxing.client.android"));
        startActivity(DownloadZxing);
        }
      else //Toast message indicating No PlayStore Found
       {
         Toast.makeText(this,"Install PlayStore First",Toast.LENGHT_SHORT).show();
        }
  }

Hope these may help!! 希望这些对您有所帮助!! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM