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.



Flashlight app in sketchware
Flashlight app in sketchware



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

Popular posts from this blog

Sketchware Generate Firebase Dynamic Link (Long Url To Short) | sketchware blocks explained

what is sketchware and history of sketchware

How to import local library in sketchware

Create HTML Dialog in Sketchware

Create Percentage loading bar in sketchware

how to import export custom blocks sketchware

Sketchware Generate Firebase Dynamic Link (Long Url To Short) | sketchware blocks explained

Android 10/11 Storage Permission sketchware | New blocks + method

Auto Get text from camera || OCR in sketchware || free project | Sketchware pro tutorial

Image filter moreblocks for making black and white imageview