在不使用意图的情况下实现条形码扫描器时出现问 [英] problem while implementing barcode scanner without using intents

查看:126
本文介绍了在不使用意图的情况下实现条形码扫描器时出现问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我去了这个网站 https://github.com/ journeyapps / zxing-android-embedded [ ^ 并实施了条形码扫描仪。但我扫描后无法获取值



我用来实现扫描仪的代码如下

< pre lang =java> IntentIntegrator integrator = new IntentIntegrator(MainActivity。 this );
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt( 扫描条形码或QR码);
integrator.setCameraId( 0 ); // 使用设备的特定摄像头
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
// integrator.addExtra(key,value);
integrator.initiateScan ();




onActivityResult中的


  @ Override  
protected void onActivityResult( int requestCode, int resultCode,Intent data){
IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,数据);
if (result!= null){
if (result.getContents( )== null){
Toast.makeText( this 已取消,Toast.LENGTH_LONG)。show();
} 其他 {
Toast.makeText( 已扫描: + result.getContents(),Toast.LENGTH_LONG)。show();
}
} 其他 {
// 这很重要,否则结果将不会传递给片段
super .onActivityResult(requestCode,resultCode,数据);
}

}




运行应用程序
我收到错误

错误:( 50  52 )错误:package com .google.zxing.client.androidlegacy.camera不存在





i已将以下库导入我的gradle文件



编译'  com.google.zxing :core:3.2.0' 
compile ' com.journeyapps:zxing-android-embedded :3.0.3 @aar'







现在如何获取扫描值?请指导我实现这个

解决方案

以这种方式尝试:

  public   void  onActivityResult( int  requestCode, int  resultCode,Intent intent){
if (requestCode == 0 ){
if (resultCode == RESULT_OK){
String 内容= intent.getStringExtra( SCAN_RESULT);
字符串 format = intent.getStringExtra( SCAN_RESULT_FORMAT);
// 处理成功扫描
} else if (resultCode == RESULT_CANCELED){
// < span class =code-comment>处理取消

}
}
}



检查:

将zxing条形码扫描仪集成到您的Android应用程序中 [ ^ ]

将ZXing库直接集成到我的Android应用程序中 [ ^ ]


i went throght this web site https://github.com/journeyapps/zxing-android-embedded[^] and have implemented a barcode scanner. but i am not able to fetch the value after it has been scanned

the code i used to implement the scanner is as follows

IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
               integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
               integrator.setPrompt("Scan a barcode or QR Code");
               integrator.setCameraId(0);  // Use a specific camera of the device
               integrator.setBeepEnabled(false);
               integrator.setBarcodeImageEnabled(true);
               //integrator.addExtra(key,value);
               integrator.initiateScan();



in onActivityResult

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result != null) {
            if(result.getContents() == null) {
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
            }
        } else {
            // This is important, otherwise the result will not be passed to the fragment
            super.onActivityResult(requestCode, resultCode, data);
        }

    }



on running the app i get an error

Error:(50, 52) error: package com.google.zxing.client.androidlegacy.camera does not exist



i have imported the following library into my gradle file

compile 'com.google.zxing:core:3.2.0'
    compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'




now how do i fetch the scan value? please guide me to achieve this

解决方案

Try in this way:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
         String contents = intent.getStringExtra("SCAN_RESULT");
         String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
         // Handle successful scan
      } else if (resultCode == RESULT_CANCELED) {
         // Handle cancel
      }
   }
}


Check :
Integrate zxing barcode scanner into your Android app[^]
Integration ZXing library directly into my Android application[^]


这篇关于在不使用意图的情况下实现条形码扫描器时出现问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆