Don't Work Access To Torch In Android Marshmallow
Camera cam = Camera.Open(); Camera.Parameters p = cam.getParameters(); p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); cam.setParameters(p); cam.startPreview(); that there is
Solution 1:
Marshmallow has a new Flashlight API with setTorchMode().
Solution 2:
Your code does not set a preview target with either Camera.setPreviewDisplay or Camera.setPreviewTexture. That's required by the API for preview to operate, though many devices unfortunately don't enforce this (which is a problem when you then run your app on a strict device).
If you don't want to draw a preview, then just create a dummy SurfaceTexture:
Cameracam= Camera.Open();
Camera.Parametersp= cam.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
SurfaceTexturedummy=newSurfaceTexture(1);
cam.setPreviewTexture(dummy);
cam.startPreview();
And make sure that you don't let the dummy SurfaceTexture object get garbage-collected while the camera is running.
That said, the new torch API in Marshmallow is very simple to use and does not require the camera permission, so I recommend you use it whenever possible.
Post a Comment for "Don't Work Access To Torch In Android Marshmallow"