1

我正在编写 android 应用程序,我的客户需要一个条形码扫描仪。他们真的很具体,所以他们想要的布局是这样的:

在此处输入图像描述

如果找到二维码 - 它会自动跳转到另一个窗口。如果手动按下 - 您会被要求手动输入并继续应用程序的其余部分。

所以基本上我可以将 zxing 代码嵌入到我的应用程序中并将其添加到活动中,但我不希望这样,并且希望将它作为一个单独的应用程序。

我目前拥有的是一个单独的活动,如下所示:

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

我也试过这个:

IntentIntegrator intentIntegrator = new IntentIntegrator(this);
Intent i = intentIntegrator.initiateCustomScan();

LocalActivityManager mgr = getLocalActivityManager();

Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;

if(wd != null) {
  scanButton.addView(wd);
}

但后来我得到 java.lang.SecurityException:

03-19 12:22:55.890: E/AndroidRuntime(29394): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.menucard.barcode.scan/com.barcode.scan.ScanActivity}: java.lang.SecurityException: Requesting code from com.google.zxing.client.android (with uid 10139) to be run in process com.menucard.barcode.scan (with uid 10169)

也许有人知道如何将单独的应用程序添加到我的活动中?或者其他方法来实现这一点?

4

2 回答 2

1

@MindaugasSvirskas, your last comment is exactly what I was about to post now:-) I have faced the same problem in the past, in several apps, and believe me, just make use of Intents, that's the way the whole Android system is designed, favouring intercommunication between apps. iOS programmers can easily integrate the scanning Zxing layout in their own layouts, but we are supposed to make use of intents, and I agree.

于 2013-03-19T12:16:45.083 回答
1

Intent不幸的是,您无法将外部应用程序嵌入到另一个应用程序中。对于初学者来说,这里的外部应用程序需要占据整个屏幕,并且处于横向模式。

您应该编写自己的应用程序,但可以在您的应用程序中重用 Barcode Scanner 的部分内容,这样它就不会完全从头开始。请不要复制AndroidManifest.xml文件。我认为考虑到不同的用户界面,它也不会与条形码扫描仪混淆。剩下的就是确保您遵守 Apache 许可证的条款(简单)。

于 2013-03-19T13:31:50.443 回答