A Flash Light App in Sketchware

To create a Torch Flashlight application for Android with Sketchware follow the steps given below.

1. Create a new project in Sketchware. In VIEW area add an ImageView imageview1. Set it's width and height to 100, and scale type to FIT_XY.

2. Using Image Manager add two images ic_flash_on_black and ic_flash_off_black.

3. Set ic_flash_off_black as the image of imageview1.

4. In Library manager switch on AppCompat and Design.

5. Add a Camera component.

6. Add two Boolean variables: flashLightStatus and hasCameraFlash.

7. Add two More Blocks: flashLightOn and flashLightOff.

8. In onCreate event, use add source directly block and put following code:
hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

9. In More Block flashLightOn, use add source directly block and put following 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) { }

10. In More Block flashLightOff, use add source directly block and put following 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) { }

11. Add imageview1 onClick event. Here use blocks as shown in image below.
12. Save and run the project. In the app, click the ImageView to switch on flash light.



Create Flashlight App using Switch
1. Create a new project in Sketchware. In VIEW area add a Switch switch1. Set it's width to match_parent, and gravity to left.

2. In Library manager switch on AppCompat and Design.

3. Add a Camera component.

4. Add two boolean: flashLightStatus
and hasCameraFlash.

5. Add two More Blocks:
 flashLightOn and flashLightOff.

6. In onCreate event, use add source directly block and put following code:
hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

7. In More Block flashLightOn, use add source directly block and put following 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; } catch (android.hardware.camera2.CameraAccessException e) { }

8. In More Block flashLightOff, use add source directly block and put following 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; } catch (android.hardware.camera2.CameraAccessException e) { }

9. Add switch1 onCheckChanged event. Here use blocks as shown in image below.

10. Save and run the project. In the app, click the Switch to switch on flash light.

Comments

  1. sir.. can you code color filter in webview in sketchware.....?

    ReplyDelete
  2. Sir plz help me how to send notifications for my app user

    ReplyDelete
  3. Sir image click after "invalid list
    index=0;
    What is this massage?please help me.

    ReplyDelete
    Replies
    1. You may have created image with different name.

      Delete
  4. I need help
    :- Sketchware shows invalid intent operation NO ACTIVITY FOUND TO HANDLE INTENT
    What does that mean
    i tried changing the intent but no difference

    shows mdisplayid=0 mbaseid=0 mflags=0

    ReplyDelete
    Replies
    1. Try creating it's relative component hope solved the problem....:)

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Nice. Visit my blog... https://www.techashik.com/2018/08/5-tools-to-add-new-features-to-gmail.html

    ReplyDelete
  7. Visit And Earn Free
    CASH 100% WORKING WITH PAYMENT PROOF


    https://bit.ly/2LztG2N

    ReplyDelete
  8. Replies
    1. This comment has been removed by the author.

      Delete
    2. Sir please help,i want to make an app with evaluation peroid,ex- 50 runs only ,but with help of firebase.

      Delete
  9. It occurs error sir. Even though I complte and correct the steps. How can I fix this ? All project is error, it cannot runs.

    ReplyDelete
  10. Nice tutorials you have here. By the way could help me to create a code that can scroll back to the top of the page by just clicking a floating action button (fab)?

    I'm creating a quite long page using sketchware and it would be helpful if there is a fab button that can scroll back to the top when we reach the bottom. Appreciate your help. Thanks.

    ReplyDelete
  11. Sir, I need help on how to create 'on volume button clicked' event which will trigger when we click volume up button and volume down button. Is this possible in sketchware? Like I want to set textview text to hello when volume up button clicked and set textview text to bye when volume down button clicked. Please help me out sir. Thanks for reading!!

    ReplyDelete
  12. Prioritizing & making anything smooth always senssse the best in any ecosystem. To protect along with run the entire process flows for all mentioned activities works properly. If someone go by the prescribed way then proper research plus authenticity is needed to proof the scenario. Substantial mechanism always shows the true path to make the documents or finished products perfect.

    ReplyDelete
  13. How to add hascameraflash
    Flashlightstatus to the script

    ReplyDelete
  14. Sir, I complete all the step above, but when I start the app and tap on the flash button , then show the toast Your device have no flash. I mean the camera detector code or logic don't compatible with my device .
    Please help me by giving another solution for stop the toast.
    My device is android 5.1 lolipop

    ReplyDelete
  15. please i have done everything in the tutorial but when i click on the flash image i get an error saying invalid list operation:length =0; index=0 please what does it mean and how do i fix it

    ReplyDelete
    Replies
    1. It means this list cameraManager.getCameraIdList()[0];
      is empty. I don't know why is it so. Maybe it doesn't work in your device or requires some modifications.

      Delete
    2. aawww that's too bad, but can you please lemme know when you figure out how to fix this issue

      Delete
  16. I can't run my app it's say errors ..

    ReplyDelete
  17. Hi can It work with other image with same name?

    However I tried with one it's not working can you solve this

    ReplyDelete
  18. Moi mon Problème c'est cette marche sur beaucoup mais pour certains non pourquoi ?

    ReplyDelete
  19. help me please :
    Invalid list operation
    : length=0; index=0

    ReplyDelete
  20. Sir I've done it all but it shows me error "hascameraflash cannot be result to variable " !!

    ReplyDelete
  21. Sir I've done it all but it shows me error "hascameraflash cannot be result to variable " !!

    ReplyDelete
  22. Back button to get out of app is not working. All else works..

    ReplyDelete
  23. Sir give code for increase brightness of flashlight

    ReplyDelete
  24. Sir give code for increase brightness of flashlight

    ReplyDelete
  25. It showing error after running it

    ReplyDelete
  26. Hello Master, am very glad to contact you. Am Emmanuel, one of your Subscribers on YouTube. I follow you how you create apps. I have make A FlashLight app and it works on some devices BUT does not work on SAMSUNG DEVICE especially Galaxy s5. Any time I open the app I get an ERROR Like This

    " An error occured
    java.lang.NoSuchMethodError:
    No virtual method
    setTorchMode(Ljava/lang/
    String,Z)V in class Landroid/
    hardware/camera2/
    CameraManager; or its super
    classes (declaration of
    'android.hardware.camera2.Cam
    eraManager appears in
    system/framework/
    framework.jar:classes2.dex)
    at
    com.ohms.flashlight.MainActivit
    y._flashLightOn(MainActivity.jav
    a:198)
    at
    com.ohms.flashlight.MainActivit
    y.access$9(MainActivity.java:
    194)
    at
    com.ohms.flashlight.MainActivit
    y$2.onClick(MainActivity.java:
    END APPLICATION

    Please can you help me fix this ERROR. Thank You

    ReplyDelete
  27. Hello @admin.

    After following this steps and your YouTube channel tutorial steps for creating a flashlight app with sketchware. I click the "run" button to compile but sketchware shows an error log. Help pls, I tried to amend it but still shows error.

    ReplyDelete
  28. Hello, I would like to appreciate your work. It’s a great platform got to learn a lot. Your data is really worthy. Thank you so much. Keep it up!

     Playbox App For Android

     Playbox Download Android

    ReplyDelete

Post a Comment

Popular posts from this blog

Create Music Player app in Sketchware

Simple car racing android game in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Firebase auth in Sketchware for Login Activity