[英]Zxing QR code scanner is turning off flush light automatically
我已經集成了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
包含割炬的配置。 但是這部分代碼尚未發布,因此您必須使用master
的快照構建。 當在所有發行版本上配置相機時, CameraManager
似乎還會關閉手電筒燈。
開始掃描之前,只需致電
qrScan.setTorchEnabled(true);
您甚至可以使用音量鍵(向上調為ON)來操作割炬。
請注意,割炬可能在任何掃描后都會關閉,因此也許不要使用setFlushLight(cameraId[0], true)
處理割炬setFlushLight(cameraId[0], true)
而只能確保以割炬標志開始掃描。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.