我已经集成了Zxing QR扫描仪库。这是我的 app/build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
testCompile 'junit:junit:4.12'
compile 'com.journeyapps:zxing-android-embedded:3.4.0'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
}
在 onCreate()
方法中我有
mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
cameraId = mCameraManager.getCameraIdList();
} catch (CameraAccessException e) {
Log.d("camera", "error");
}
setFlushLight(cameraId[0], true);
因此,应用程序启动时,同花灯会打开。然后,我按下“启动 QR 扫描仪”按钮,启动 QR 扫描仪,然后我会得到预期的解析结果。
这是用于解析二维码的代码:
private IntentIntegrator qrScan;
//Getting the scan results
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
String latestScannedData;
if (result != null) {
if (result.getContents() == null) {
//if qrcode has nothing in it
Toast.makeText(this, "Result Not Found", Toast.LENGTH_LONG).show();
} else {
//if qr contains data
latestScannedData = result.getContents();
latestScannedTime = System.currentTimeMillis();
if (latestScannedData.equals(previousData)) {
//if this data equals previous data
//tell to remove the card
if (latestScannedTime - previousScanTime > n * 1000) {
//if last scan was more than n seconds ago
t1.speak("Please remove the card", TextToSpeech.QUEUE_FLUSH, null);
previousData = "";
}
qrScan.initiateScan();
} else {
t1.speak("Access granted", TextToSpeech.QUEUE_FLUSH, null);
qrScan.initiateScan();
previousData = latestScannedData;
previousScanTime = System.currentTimeMillis();
}
Log.d("qrresult", result.getContents());
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
我的问题是:
ZXing QR扫描仪自动关闭冲洗灯(我的要求是在黑暗环境中扫描,所以灯是强制性的)
我还发布了我的日志的一部分:
D/CameraPreview: resume()
D/CameraInstance: Opening camera
D/CameraInstance: Configuring camera
I/CameraManager: Camera Display Orientation: 90
I/CameraConfiguration: Requesting focus mode value from among: [auto]
I/CameraConfiguration: Supported focus mode values: [auto, infinity, fixed, macro, continuous-video, continuous-picture, manual]
I/CameraConfiguration: Can set focus mode to: auto
I/CameraConfiguration: Focus mode already set to auto
I/CameraConfiguration: Requesting flash mode value from among: [off]
I/CameraConfiguration: Supported flash mode values: [off, auto, on, torch]
I/CameraConfiguration: Can set flash mode to: off
I/CameraConfiguration: Flash mode already set to off
I/PreviewScalingStrategy: Viewfinder size: 1920x1080
I/CameraPreview: Starting preview
D/CameraInstance: Starting preview
D/OpenGLRenderer: endAllStagingAnimators on 0x55a98da7b0 (RippleDrawable) with handle 0x55a9894a00
I/AutoFocusManager: Current focus mode 'auto'; use auto focus? true
如何保持同光灯打开?
最佳答案
IntentIntegrator
包含 torch 的配置。但这部分代码尚未发布,因此您必须使用 master
的快照构建。在所有发布的版本上配置相机时,CameraManager
似乎还会关闭手电筒灯。
未发布的方法
在开始扫描之前,只需调用
qrScan.setTorchEnabled(true);
您甚至可以使用音量键来操作手电筒,其中向上键打开。
请注意,手电筒可能会在任何扫描后关闭,因此可能不要使用 setFlushLight(cameraId[0], true)
处理它,而仅确保扫描以 torch 旗。
关于java - Zxing 二维码扫描仪自动关闭冲洗灯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57635560/