I am trying to create a parameter such as the SOS module in my application, I am creating code for this:
class SOSModule { private Camera camera; private Camera.Parameters params; private boolean isFlashOn; void blink(final int delay, final int times) { Thread t = new Thread() { public void run() { try { for (int i=0; i < times*2; i++) { if (isFlashOn) { turnOffFlash(); } else { Camera.open(); turnOnFlash(); } sleep(delay); } } catch (Exception e){ e.printStackTrace(); } } }; t.start(); } void turnOnFlash() { if (!isFlashOn) { if (camera == null || params == null) { return; } params = camera.getParameters(); params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); camera.setParameters(params); camera.startPreview(); isFlashOn = true; } } void turnOffFlash() { if (isFlashOn) { if (camera == null || params == null) { return; } params = camera.getParameters(); params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); camera.setParameters(params); camera.stopPreview(); isFlashOn = false; } }
}
I also add all the necessary permissions to the manifest, and of course I check the usage on time.
But this is not work. I am just creating another code, but working as a "one flash" without any loop.
Can you guys help me?
Guys, this is important for me, I canβt do it because my Huawei p8 Lite and p9 Lite do not give any errors when this happens, there is a problem with the Huawei software, with the camera that I have to check on the psychic device, and it The big problem is that I don't have logs from devices.
public void flash_effect() throws InterruptedException { cam = Camera.open(); final Camera.Parameters p = cam.getParameters(); p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); Thread a = new Thread() { public void run() { for(int i =0; i < 10; i++) { cam.setParameters(p); cam.startPreview(); try { Thread.sleep(50); } catch (InterruptedException e) {
This code worked, but the flash is open for infinity without any blink effect Any ideas ??
source share