zxing 循环扫描_安卓Zxing 扫码如何连续扫码
在CaptureActivity类中找到以下方法:/*** Handler scan result** @param result* @param barcode*/public void handleDecode(Result result, Bitmap barcode){inactivityTimer.onActivity();playBeepSoundAndVibrate();String
在CaptureActivity类中找到以下方法:
/**
* Handler scan result
*
* @param result
* @param barcode
*/
public void handleDecode(Result result, Bitmap barcode)
{
inactivityTimer.onActivity();
playBeepSoundAndVibrate();
String resultString = result.getText();
doResult(resultString);
}
/**
* 增加的部分:对扫描返回的结果进行处理
*/
private void doResult(String result)
{
if (result.equals(""))
{
ToastUtil.showToastByThread(getApplicationContext(),
"二維碼掃描失敗,請手動輸入!");
} else
{
mHandler.postDelayed(runnable, 1000);
}
}
/**
* 增加的部分:实现多次重复扫描,否则本界面打开一次,只能聚焦一次,扫描一次。增加这一部分之后就能连续聚焦,连续扫描
*/
Handler mHandler = new Handler();
Runnable runnable = new Runnable()
{
@Override
public void run()
{
if (handler != null)
{
try
{
mHandler.postDelayed(runnable, 1000);
handler.restartPreviewAndDecode(); // 实现多次扫描
} catch (Exception e)
{
e.printStackTrace();
}
}
}
};
更多推荐
所有评论(0)