【发布时间】:2014-04-10 22:53:56
【问题描述】:
在询问之前我已尽力找到解决方案,但是,我似乎找不到类似的情况。
我已经为我正在开发的应用程序实现了 QR 扫描仪。我正在使用 zxing 库,特别是使用下面的导入。此外,这些应用程序使用来自 Play 商店的“条形码扫描仪”(我被提示安装)。
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
问题是扫描仪每 3-6 次扫描只能工作 1 次。我要么得到一个空返回,要么没有输出。它总是返回到我的源屏幕,从不产生实际错误。
我使用本教程作为来源:Android SDK: Create a Barcode Reader
这是来自 mainactivity 的相关信息:
public void onClick(View v){
//respond to clicks
if(v.getId()==R.id.scanQRButton){
//scan
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
formatTxt.setText( "Scan Initiated");
contentTxt.setText(" Scan Results: " + scanContent);
if(scanContent != null){
String userid,medname,tabstaken,dob;
StringTokenizer st = new StringTokenizer(scanContent, ",");
// token 0
dob = st.nextToken();
//token 1
medname = st.nextToken();
//token 2
tabstaken = st.nextToken();
//token 3
//rxnumber
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
HashMap<String,String> user = new HashMap<String, String>();
user = db.getUserDetails();
//Store the userlog by passing to UserLogEntry
userid = user.get("uid");
//debug.setText("Userid: "+ userid+ " medname: " + medname + " tabs: " +tabstaken);
UserLogEntry userlog = new UserLogEntry(getApplicationContext(),userid,medname,tabstaken);
userlog.addUserLog();
}
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
//we have a result
scanContent = scanningResult.getContents();
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
这是我正在使用的库包中的 ZXing 类:
意图结果:
IntentIntegrator:
关于如何让它在 %100 的时间内工作的任何想法?
谢谢!
【问题讨论】: