gpt4 book ai didi

android - 条码扫描器无结果

转载 作者:太空狗 更新时间:2023-10-29 14:28:44 26 4
gpt4 key购买 nike


我正在使用 ZXING IntentIntegrator 来读取 URL。我设法使用以下方法启动了条码扫描器:

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

条形码扫描仪指示已找到一个 URL,并将我重定向回我的应用程序,我在其中使用以下方法检索信息:

@Override
protected 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");
Toast.makeText(getApplicationContext(), contents, Toast.LENGTH_LONG).show();
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}


}

问题是,即使找到了一个 URL,requestCode 是 -1 并且 intent 没有数据。
有谁知道我的问题的根源是什么?

附言
我尝试实现 onActivityResultListener 但出现以下错误:

The return type is incompatible with PreferenceManager.OnActivityResultListener.onActivityResult(int, int, 
Intent)

最佳答案

为什么你期望 resultCode 不是 -1resultCode 用于确定 Intent ,即您为结果调用 Activity 的“原因”。仅此而已...我只是删除 if (requestCode == 0) 因为它不是很重要。

关于android - 条码扫描器无结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9152454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com