HomeSketchwareHow to make a Flashlight App in Sketchware App

How to make a Flashlight App in Sketchware App

1) Create a New project in Sketchware.

2) In view area add a LinearLayout as linear1 and set it’s layout to center horizontal and center vertical.
Then add Imageview as imageview1. Set it’s width and height to 100dp and scale type to FIT_XY.
Then on image manager add two images
ic_flash_on_black and ic_flash_off_black.
Set imageview1 to ic_flash_off_black.

3) In library manager switch on AppCompat and Design.

4) Add a Camera component.

5) Add two Boolean Variables as flashLightStatus and hasCameraFlash.

6) Add two more blocks as flashLightOn and flashLightOff.

7) In OnCreate event add an add source directly block with code:

hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);


8) In More block flashLightOn add a add source directly block with code:
android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);

try {

String cameraId = cameraManager.getCameraIdList()[0]; cameraManager.setTorchMode(cameraId, true);

flashLightStatus = true; imageview1.setImageResource(R.drawable.ic_flash_on_black); } catch (android.hardware.camera2.CameraAccessException e) { }


9) On more block flashLightOff  add a add source directly block with code:
android.hardware.camera2.CameraManager cameraManager = (android.hardware.camera2.CameraManager) getSystemService(Context.CAMERA_SERVICE);

try {

String cameraId = cameraManager.getCameraIdList()[0]; cameraManager.setTorchMode(cameraId, false);

flashLightStatus = false; imageview1.setImageResource(R.drawable.ic_flash_off_black); } catch (android.hardware.camera2.CameraAccessException e) { }

10) Add imageview1 click event and add the following block as shown below.

That’s all.
Save and run the project.
You can watch the below video.


Leave a Reply