HOW TO CREATE FLASHLIGHT APP WITH SKETCHWARE


In this post we are going to learn how to create a Flashlight App with Sketchware using this simple steps:





STEPS ON CREATING A FLASHLIGHT APP:





Open your sketchware app and click on create a new app (project).




Create a package and a project name




Drag a vertical linear layout and set the width to match parent




Drag two horizontal linear layouts and set the weight of the bottom horizontal layout to 50




Set the weight of the top horizontal linear layout to 5.




Click on view and turn off the toolbar




Go to Library Manager and turn on App Compat and Design




Go to Image Manager and add two images: torchon and torchoff. The images can be gotten from Here




Go to view,and click on linear3 and set the background resource as torchoff




Click on linear2 and add an imageview




And change the scale type of the imageview to fit center




Add a textview to linear2 and set the width to match parent




Go to Image Manager and add any image of your choice to use as your Flashlight app logo




Change the text in the textview to the name of your flashlight and increase the text size to 20sp




And set the text style of the textview to bold








Go to Activity On Create and create two Boolean variables (Flash and flashLightStatus)




Go to view and set the height of linear2 to 50 and set the background color of linear2 to any color of your choice




Go to on Activity Create,click on operator and click on add source directly




Click on add source directly and put; Flash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);




Go to moreblocks and create two moreblocks (flashOn and flashOff)




Go to flashOn moreblock,click on operator and click on add source directly and add this; 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;} catch (android.hardware.camera2.CameraAccessException e) { }




Go to flashOff moreblock, click on add source directly and put this; 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; } catch (android.hardware.camera2.CameraAccessException e) { }




Go to view screen,and set the background color of linear 1 to any color of your choice








Go to component and add a camera component and name it camera




Go to view and click on linear3 on event and copy what's in the image.




Click on Save and Run the app




Please like, share and subscribe to our YouTube channel


Post a Comment

2 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.