How to make a Flashlight App in Sketchware App
1) Create a New project in Sketchware.
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.
4) Add a Camera component.
5) Add two Boolean Variables as flashLightStatus and hasCameraFlash.
6) Add two more blocks as flashLightOn and flashLightOff.
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) { }
Save and run the project.
You can watch the below video.
Comments
Post a Comment