ZXing 条码扫描仪在 ActivityGroup 内失败

发布于 2024-11-28 02:13:30 字数 1971 浏览 1 评论 0原文

我创建了一个小的 tabActivity 应用程序,并且喜欢运行 zxing 并显示结果,而无需使用 ActivityGroup 更改选项卡。 没有 ActivityGroup 一切正常。

这是我的 ScanActivity 的一些代码。如果我“启用”activityGroup,我将永远不会遇到 onActivityResult...:

  class ScanButtonClickListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            IntentIntegrator.initiateScan(BarcodeActivity.this);
        }
    }  

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
           IntentResult scanResult = 
                IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
           Log.v("barcode", scanResult.getContents().toString());
   }

以下是清单的一部分:

activity android:name=".barcode.BarcodeActivity"
 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
 android:screenOrientation="portrait">
</activity>     
<activity android:name=".tabGroups.BarcodeTabGroupActivity"></activity> 

和 TabGroupActivity,它现在仅启动 BarcodeActivity:

public class BarcodeTabGroupActivity extends TabGroupActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("BarcodeActivity", new Intent(this, BarcodeActivity.class));
    }
}

以及过滤后的日志:

08-04 15:59:02.093: DEBUG/DecodeHandler(4477): 在 1 毫秒内找到条形码
08-04 15:59:02.144: DEBUG/CaptureActivityHandler(4477): 解码成功消息
08-04 15:59:03.792: DEBUG/CaptureActivityHandler(4477): 收到返回扫描结果消息
android::CameraHardwareSec::stopPreview() :预览未运行,不执行任何操作
08-04 15:59:03.941:INFO/WindowManager(109):将旋转设置为 0,animFlags=1
08-04 15:59:03.957:​​INFO/ActivityManager(109):配置已更改:{scale=1.0 imsi=0/0 loc=en_US touch=3 键=1/1/2 nav=1/1 orien=1 布局=34 uiMode=17 seq=72}

我认为这一定是 ActivityManager 的问题。一旦 zxing 结束,它就会返回显示按钮,但没有结果。

有什么建议吗?提前致谢!

i created a little tabActivity application and like to run zxing and display the result without changing the tab using an ActivityGroup.
Everything works fine without the ActivityGroup.

And here's some code of the my ScanActivity. If i "enable" the activityGroup i'll never run into the onActivityResult...:

  class ScanButtonClickListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            IntentIntegrator.initiateScan(BarcodeActivity.this);
        }
    }  

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
           IntentResult scanResult = 
                IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
           Log.v("barcode", scanResult.getContents().toString());
   }

Here are parts of the manifest:

activity android:name=".barcode.BarcodeActivity"
 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
 android:screenOrientation="portrait">
</activity>     
<activity android:name=".tabGroups.BarcodeTabGroupActivity"></activity> 

and the TabGroupActivity, which only launches the barcodeActivity for now:

public class BarcodeTabGroupActivity extends TabGroupActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("BarcodeActivity", new Intent(this, BarcodeActivity.class));
    }
}

And a filtered log:

08-04 15:59:02.093: DEBUG/DecodeHandler(4477): Found barcode in 1 ms
08-04 15:59:02.144: DEBUG/CaptureActivityHandler(4477): Got decode succeeded message
08-04 15:59:03.792: DEBUG/CaptureActivityHandler(4477): Got return scan result message
android::CameraHardwareSec::stopPreview() : preview not running, doing nothing
08-04 15:59:03.941: INFO/WindowManager(109): Setting rotation to 0, animFlags=1
08-04 15:59:03.957: INFO/ActivityManager(109): Config changed: { scale=1.0
imsi=0/0 loc=en_US touch=3 keys=1/1/2 nav=1/1 orien=1 layout=34
uiMode=17 seq=72}

I think it must be something with the ActivityManager.. as soon as zxing ends, it returns showing the button and no result.

Any tips? thanks in advanced!!

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

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

发布评论

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

评论(1

山川志 2024-12-05 02:13:30

好吧,我自己设法解决了这个问题。
对于对我的解决方案感兴趣的每个人,这里是:

我没有启动对子活动“BarcodeActivity”的扫描,而是将其引用到父活动:

class ScanButtonClickListener implements OnClickListener {
    @Override
    public void onClick(View v) {
            //get the parent activity
        TabGroupActivity parentActivity = (TabGroupActivity) getParent();
        IntentIntegrator.initiateScan(parentActivity);
    }
}  

现在可以通过父 BarcodeTabGroupActivity 中的 onActivityResult 访问结果:

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    Log.v("barcode_tabgroup", scanResult.getContents().toString());
  }

在此onActivityResult 我现在可以启动下一个 childActivity 来处理扫描结果...不知道这是否是好的做法,但它有效。

我以为我必须使用来完成其他儿童活动

BarcodeActivity childActivity = (BarcodeActivity) getCurrentActivity();
childActivity.finish();

,但随后它击落了所有东西..

Ok, i managed to solve this problem on my own.
For everyone who's interested in my solution, here it is:

Instead of initiate the scan on the child activity "BarcodeActivity", i refered it to the parent activity:

class ScanButtonClickListener implements OnClickListener {
    @Override
    public void onClick(View v) {
            //get the parent activity
        TabGroupActivity parentActivity = (TabGroupActivity) getParent();
        IntentIntegrator.initiateScan(parentActivity);
    }
}  

And now it's possible to access the result via onActivityResult within the parent BarcodeTabGroupActivity:

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    Log.v("barcode_tabgroup", scanResult.getContents().toString());
  }

Within this onActivityResult i'm now able to start my next childActivity to process the scan results... don't know if that's good practice, but it works.

I thought i have to finish the other child activity using

BarcodeActivity childActivity = (BarcodeActivity) getCurrentActivity();
childActivity.finish();

but then it shoots down everything..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文