2013-01-03 77 views
3

我在使用zxing掃描程序時遇到Exception。在我的應用程序中,我想通過單攝像頭Activity(zxing的CaptureActivity)掃描BarQR代碼。對於我用下面的代碼在我的應用程序Zxing問題 - ActivityNotFoundException

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

但我正在逐漸例外: -

01-03 10:28:15.445: E/AndroidRuntime(3405): android.content.ActivityNotFoundException: No Activity found to handle Intent 
{ act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) } 

我不能在我的應用程序使用

IntentIntegrator 

。所以請有人幫助我解決這個問題。 這是我的完整日誌貓輸出

   01-04 04:58:39.551: D/AndroidRuntime(905): Shutting down VM 
        01-04 04:58:39.551: W/dalvikvm(905): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 
         01-04 04:58:39.581: E/AndroidRuntime(905): FATAL EXCEPTION: main 
         01-04 04:58:39.581: E/AndroidRuntime(905): 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-04 04:58:39.581: E/AndroidRuntime(905): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545) 
         01-04 04:58:39.581: E/AndroidRuntime(905): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416) 
        01-04 04:58:39.581: E/AndroidRuntime(905):  at android.app.Activity.startActivityForResult(Activity.java:3351) 
        01-04 04:58:39.581: E/AndroidRuntime(905):  at android.app.Activity.startActivityForResult(Activity.java:3312) 
         01-04 04:58:39.581: E/AndroidRuntime(905): at com.google.zxing.shopping.shopping$1.onClick(shopping.java:98) 
          01-04 04:58:39.581: E/AndroidRuntime(905): at android.view.View.performClick(View.java:4084) 
         01-04 04:58:39.581: E/AndroidRuntime(905): at android.view.View$PerformClick.run(View.java:16966) 
         01-04 04:58:39.581: E/AndroidRuntime(905):  at android.os.Handler.handleCallback(Handler.java:615) 
         01-04 04:58:39.581: E/AndroidRuntime(905):  at android.os.Handler.dispatchMessage(Handler.java:92) 
           01-04 04:58:39.581: E/AndroidRuntime(905): at android.os.Looper.loop(Looper.java:137) 
          01-04 04:58:39.581: E/AndroidRuntime(905): at android.app.ActivityThread.main(ActivityThread.java:4745) 
          01-04 04:58:39.581: E/AndroidRuntime(905): at java.lang.reflect.Method.invokeNative(Native Method) 
          01-04 04:58:39.581: E/AndroidRuntime(905): at java.lang.reflect.Method.invoke(Method.java:511) 
         01-04 04:58:39.581: E/AndroidRuntime(905): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
         01-04 04:58:39.581: E/AndroidRuntime(905): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
           01-04 04:58:39.581: E/AndroidRuntime(905): at dalvik.system.NativeStart.main(Native Method) 

在此先感謝所有

回答

1

你得到ActivityNotFoundException作爲斑馬線應用程序未安裝在設備中。所以請檢查它是否安裝。如果不是,那麼將用戶重定向到Zxing的Playstore頁面:

我已經爲這些實現了一些代碼。根據您的需要修改:

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

希望這些可以幫助! :)

+0

@Patel ..有可能在不使用第三方應用程序的情況下掃描qr和條碼。我只是在我的項目中複製了所有zxing包的粘貼。感謝您的答覆。我請幫我 – DJhon

+0

@這意味着我問沒有安裝任何其他應用程序。 – DJhon

+0

當然,這是可能的,但這是另一個問題。 –