Zxing 1.7 和 Android API 15 - 扫描仪导致摩托罗拉设备上的应用程序崩溃

发布于 2025-01-02 22:55:05 字数 1827 浏览 2 评论 0原文

我有 Zxing 1.7 和 Android api 15。通过 Intent 集成扫描仪并添加 CaptureActivity,以便应用程序不会询问要使用哪个相机。创建 core.jar 并将其添加到 Android 项目 lib 中,并将 Zxing Android 作为库项目添加到我的项目中构建路径。 当我单击应用程序的“san”选项卡时,扫描仪无法工作并且应用程序第一次崩溃,但下次当我重新登录我的应用程序时,它可以使用相同的功能并且可以扫描条形码。 当应用程序第一次崩溃时,它会为 CaptureActivity 提供 ClassNot Found 异常。我已遵循所有要求的步骤,并在 Manifst.xml 文件中添加了 CaptureActivity。 请提供建议,因为我已经尝试了很多替代方案。 Zxing 是否仅适用于现已过时且其替代品为 10 的 Android API9?下面是我的 ScanActivity 的代码

public void onCreate(Bundle savedInstanceState) 
  {         
    super.onCreate(savedInstanceState);        
    //Scan code
    Intent intent= new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

    //To aviod the complete action using dialog box
    intent.setClassName(this, "com.google.zxing.client.android.CaptureActivity"); 

    startActivityForResult( intent, 0 );

    //getApplicationContext().startActivity( intent );
    //View scanView = ((ActivityGroup) context).getLocalActivityManager().startActivity(id, newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();

    /*
    Intent i = new Intent(Intent.ACTION_MAIN);
    PackageManager manager = getPackageManager();
    i = manager.getLaunchIntentForPackage( "com.google.zxing.client.android.SCAN" );
    i.addCategory( Intent.CATEGORY_LAUNCHER );
    startActivityForResult( i, 0);
    */
   }

  public void onActivityResult(int requestCode, int resultCode, Intent intent)
  {
    System.out.println("ScanRewardCodeActivity OnActivityResult Method");
    if(requestCode == 0)
    {
      //Stop QR Code Reader intent
      finishActivity( 0 );

      TabActivity tabActivity = (TabActivity)getParent();
      TabHost tabHost = tabActivity.getTabHost();

      if(resultCode == RESULT_OK){
       System.out.println("Done");
      }
    }
 }

I have Zxing 1.7 and Android api 15. Integrated the scanner through Intent and added CaptureActivity so that application does not ask for which camera to use.Created core.jar and added it in Android project lib and added Zxing Android as library project to my project build path.
The scanner does not work and application crashes first time when i click on "san" tab of my app but next time the same functionality it works when i login back in my app and barcode can be scanned.
When the application crashes for first time it give ClassNot Found exception for CaptureActivity . I have followed all the requires steps and also added CaptureActivity in the Manifst.xml file.
Please advice as i have tried lots of alternatives. Does Zxing works only with Android API9 that is made obsolete now and its replacement is 10? Below is code for my ScanActivity

public void onCreate(Bundle savedInstanceState) 
  {         
    super.onCreate(savedInstanceState);        
    //Scan code
    Intent intent= new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

    //To aviod the complete action using dialog box
    intent.setClassName(this, "com.google.zxing.client.android.CaptureActivity"); 

    startActivityForResult( intent, 0 );

    //getApplicationContext().startActivity( intent );
    //View scanView = ((ActivityGroup) context).getLocalActivityManager().startActivity(id, newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();

    /*
    Intent i = new Intent(Intent.ACTION_MAIN);
    PackageManager manager = getPackageManager();
    i = manager.getLaunchIntentForPackage( "com.google.zxing.client.android.SCAN" );
    i.addCategory( Intent.CATEGORY_LAUNCHER );
    startActivityForResult( i, 0);
    */
   }

  public void onActivityResult(int requestCode, int resultCode, Intent intent)
  {
    System.out.println("ScanRewardCodeActivity OnActivityResult Method");
    if(requestCode == 0)
    {
      //Stop QR Code Reader intent
      finishActivity( 0 );

      TabActivity tabActivity = (TabActivity)getParent();
      TabHost tabHost = tabActivity.getTabHost();

      if(resultCode == RESULT_OK){
       System.out.println("Done");
      }
    }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2025-01-09 22:55:05

这里存在很多问题。

  • 如果您使用 Intents,则不需要 core/android/ 代码。确保从项目中删除所有这些代码,因为我认为它们会干扰并导致崩溃。
  • 你不应该修改你的 AndroidManifest.xml
  • 是的 zxing 1.7 适用于所有版本直到 4.0.x,但是,你应该使用几天前发布的 zxing 2.0
  • 不要尝试编写自己的集成代码。使用 android-integration/ 中给出的代码,因为它确实有效

There are a number of problems here.

  • If you are using Intents, you do not need core/ or android/ code. Make sure to remove all of this code from your project as I think it is interfering and causing the crash.
  • You should not modify your AndroidManifest.xml
  • Yes zxing 1.7 works with all versions through to 4.0.x, but, you should use zxing 2.0 which was released a few days ago
  • Don't try to write your own integration code. Use the code given in android-integration/ as it definitely works
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文