light app in sketchware
Flashlight app in sketchware pro is the most searched and most asked project in sketchware pro community but sketchware pro do not provide functionality turn on and turn off flashlight.
In this post I'll tell two method to turn on and turn off flashlight programmatically using codes in sketchware pro.
Turn on flashlight in sketchware
To turn on flashlight copy and paste this code in add source directly of sketchware pro.
android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String cameraId = cameraManager.getCameraIdList()[0]; cameraManager.setTorchMode(cameraId, true); } catch (android.hardware.camera2.CameraAccessException e) { }
You can use this code in onclick event.
Turn off flashlight in sketchware pro
To turn off flashlight there is another code, copy and paste this code in sketchware pro. Use this code in add source directly of sketchware pro.
android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String cameraId = cameraManager.getCameraIdList()[0]; cameraManager.setTorchMode(cameraId, false); } catch (android.hardware.camera2.CameraAccessException e) { }
After using both these codes just build and run your project to confirm that there is no error in these codes.
Use both codes in just one button
You can do this simple task using a boolean block and one if then block as shown in picture.
You can customise these codes as per your needs and if you need i'll provide you the blocks for flashlight in sketchware.
Download project
Link:
Comments