如何从条形码中检索产品 ID?

发布于 2024-11-11 14:34:40 字数 1733 浏览 2 评论 0 原文

我使用了与 Zxing Intent 相同的方式从我的应用程序中打开扫描仪。但我的应用程序只是打开扫描仪,什么也不做。另外,我收到一些 FileNotfoundException。

我需要在清单中添加任何权限吗?

这是我使用 Intent 的课程:

public class BarCodes extends Activity {

   /** Called when the activity is first created. */
   @Override public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button ok;

      ok=(Button) findViewById(R.id.b1);
      ok.setOnClickListener(new View.OnClickListener() {  

         @Override public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.setPackage("com.google.zxing.client.android");
            intent.putExtra("SCAN_MODE","QR_CODE_MODE");
            startActivityForResult(intent, 0);
         }

      });
      System.out.println("SSSSSSSSSSSSS");
   }

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

LogCat 也在这里:

java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}  
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System   Loader…  

可能是什么问题?

I have used the same way of Zxing Intent to open scanner from my application. But my application just opens scanner and does nothing. Also, I am getting some FileNotfoundException.

Do I have to add any permission in manifest?

This is my class where I use Intent:

public class BarCodes extends Activity {

   /** Called when the activity is first created. */
   @Override public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button ok;

      ok=(Button) findViewById(R.id.b1);
      ok.setOnClickListener(new View.OnClickListener() {  

         @Override public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.setPackage("com.google.zxing.client.android");
            intent.putExtra("SCAN_MODE","QR_CODE_MODE");
            startActivityForResult(intent, 0);
         }

      });
      System.out.println("SSSSSSSSSSSSS");
   }

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

Also LogCat is here:

java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}  
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System   Loader…  

What might be the problem??

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

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

发布评论

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

评论(3

遗弃M 2024-11-18 14:34:40

此处此处。至于为什么会收到 FileNotFoundException,您必须提供更多详细信息,例如您调用 Zxing 意图的代码以及 logcat 堆栈跟踪。

This question is answered in more detail here and here. As to why you are getting the FileNotFoundException you'd have to provide more detail, such as the code for which you are invoking the Zxing intent as well as the logcat stack trace.

帅冕 2024-11-18 14:34:40

你的错误与项目无关。 Android 表示无法找到您的类 com.pkg.Scan。您必须修复项目设置。

不过,我进一步建议您不要尝试编写自己的代码,而是使用提供的代码由项目通过Intent进行集成。

Your error is nothing to do with the project. Android is saying it is unable to find your class, com.pkg.Scan. You'll have to fix your project setup.

However I'd further suggest that you not try to write your own code, but use the code provided by the project to integrate via Intent.

你丑哭了我 2024-11-18 14:34:40

步骤:

  1. 安装 Apache Ant(http://www.youtube.com/watch?v=XJmndRfb1TU ,此视频将帮助您做到这一点)并参考 http://ant.apache.org/ 了解更多信息并下载 ant
  2. 从 ZXing 主页下载 ZXing 源代码并解压(更多信息:http://code.google.com /p/zxing/source/browse/trunk/android/)
  3. 使用 Windows 命令行(运行 -> CMD)导航到提取的目录
  4. 输入“ant -f core/build.xml”或“ant -f android/” build.xml'
  5. 进入Eclipse->新建Android项目
  6. 右键项目文件夹->属性-> Java 构建路径 ->图书馆->添加外部 JAR
  7. 如果您的 Android 设备上安装了条形码扫描仪,您只需向其发送 Intent,就可以让它为您扫描并返回结果。例如,您可以连接一个按钮来扫描二维码,这样
  8. 它会将产品代码存储在字符串值“contents”中
    以您自己的方式实现 BarCode,享受 BarCode 的乐趣 :-)

Steps:

  1. Install Apache Ant (http://www.youtube.com/watch?v=XJmndRfb1TU , this video will help you to do that) and also refer http://ant.apache.org/ for more info and download ant
  2. Download the ZXing source from ZXing homepage and extract it (For More info :http://code.google.com/p/zxing/source/browse/trunk/android/)
  3. With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
  4. Type 'ant -f core/build.xml' or 'ant -f android/build.xml'
  5. Enter Eclipse -> new Android Project
  6. Right-click project folder -> Properties -> Java Build Path -> Library -> Add External JARs
  7. If the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code in this way
  8. It will have the product code Stored in the String value 'contents'
    Have fun with BarCode by implementing it in your own way :-)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文