【问题标题】:Adding result return to BarcodeEye (ZXing glass port), what is the result location?将结果返回到 BarcodeEye(ZXing 玻璃端口),结果位置在哪里?
【发布时间】:2014-01-11 23:54:08
【问题描述】:

我正在尝试创建一个可以扫描条形码并使用条形码中的信息打开特定文档的 Glass 应用程序。

在从 Glass 的源代码构建 ZXing 遇到问题后,我转向了一个已经创建的名为 BarcodeEye 的端口:https://github.com/BarcodeEye/BarcodeEye

但是,BarcodeEye 似乎没有内置支持将其用作意图。我将意图操作添加到清单中。这使我可以从我的应用程序调用 BarcodeEye,但我无法从哪里调用 setResult 以便从barcodeEye 获得带有我的 QR 文本的结果。

任何有 ZXing 经验的人可以帮助我理解为什么没有返回结果以及在哪里放置 setResult 代码以正确返回结果。

这是我在应用中调用 BarcodeEye 的代码:

    Intent intent = new Intent("com.github.barcodeeye.SCAN");
       intent.putExtra("SCAN_MODE", "QR_CODE_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
       intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
       startActivityForResult(intent, 0);

这是我的结果类:

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                    String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
                    Log.v("zxing",contents);
            } else 
            if (resultCode == RESULT_CANCELED) {
              // Handle cancel
            }
        }
    }

任何有关如何获得正确活动结果的帮助将不胜感激。

编辑:

通过添加意图过滤器并将数据返回放在CaptureActivity.java 类中,我能够让它勉强工作。这对我有用,因为我关心的 QR 只是文本,但我认为我当前的方法在某些情况下不起作用,因为它不会通过过滤器运行它来检查它是什么类型的 QR。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.chut.glass.xively"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="15" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher_xi"
        android:label="@string/app_name" >

        <uses-library
            android:name="com.google.android.glass"
            android:required="true" />

        <activity
            android:name="com.chut.glass.xively.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data
                android:name="com.google.android.glass.VoiceTrigger"
                android:resource="@xml/voice_trigger" />
        </activity>

        <service android:name="com.jessefarebro.mqtt.MqttService" android:exported="false" />

    </application>



</manifest>

这是我最终将数据返回放入 CaputreActivity 的地方:

// Put up our own UI for how to handle the decoded contents.
private void handleDecodeInternally(Result rawResult, Bitmap barcode) {

    Uri imageUri = null;
    String imageName = IMAGE_PREFIX + System.currentTimeMillis() + ".png";
    Log.v(TAG, "Saving image as: " + imageName);
    try {
        imageUri = mImageManager.saveImage(imageName, barcode);
    } catch (IOException e) {
        Log.e(TAG, "Failed to save image!", e);
    }

    ResultProcessor<?> processor = ResultProcessorFactory
            .makeResultProcessor(this, rawResult, imageUri);

    Intent data = new Intent();
    data.putExtra("SCAN_RESULT", rawResult.toString());
   if (getParent() == null) {
       setResult(Activity.RESULT_OK, data);
       Log.v(TAG,"parent null");
   } else {
       Log.v(TAG,"parent: " + getParent());
       getParent().setResult(Activity.RESULT_OK, data);
   }
   Log.v(TAG,"about to finish");
   finish();
   Log.v(TAG,"post finish");

    //startActivity(ResultsActivity.newIntent(this, processor.getCardResults(), imageUri));
}

【问题讨论】:

  • 你能给我看看你的清单文件吗?
  • 什么没有开箱即用?
  • 我在从源代码编译 ZXing 时遇到了问题(我遇到了问题,因为它使用 Java 7 功能,但我无法在选择 java 7 的情况下编译它),但 BarcodeEye 编译得很好,但是在查看它的清单,没有内置的意图。

标签: android-intent zxing google-glass google-gdk


【解决方案1】:

我有一个 BarcodeEye 的分支,我在其中恢复/添加了 ZXing 的 Intent 功能: https://github.com/paulpv/BarcodeEye/tree/intent 我已经在上游打开了一个拉取请求,看看 BarcodeEye 是否会接受它。 我还在讨论编写他们的条码扫描仪 (CaptureActivity) 的官方 GDK Glassware 版本的可能性

【讨论】:

  • 没有人阻止任何人贡献端口——欢迎您现在添加端口。由于我没有设备,因此不会自行发生。
  • 感谢您的分叉!但我有个问题;有没有什么方法可以使用你的 fork 来调用 Barcodeeye 活动,而无需在设备上安装 Barcodeye.apk?
  • @swooby 你好!我有点晚了,但我发现你的回答和你的工作非常有用。但我无法为 Intent 设置扫描格式。我添加了一个额外的字符串“SCAN_FORMATS”=“CODE_128”,但它仍然只查找 QRCode。我已经在您的代码中查找了一段时间,但无法找到问题所在...您能告诉我吗?干杯:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-01
  • 2011-07-27
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多