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
    Replies
    1. This comment has been removed by the author.

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

    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. How to add hascameraflash
    Flashlightstatus to the script

    ReplyDelete
  13. 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
  14. 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
  15. I can't run my app it's say errors ..

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

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

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

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

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

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

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

    ReplyDelete
  22. It showing error after running it

    ReplyDelete
  23. 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
    Replies
    1. Yes i have samsung galaxy core prime and it doesnt work either have you firgured tbis out yet??

      Delete
    2. Yes i have samsung galaxy core prime and it doesnt work either have you firgured tbis out yet??

      Delete
  24. 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
    Replies
    1. Pls what did he tell you as the solution because after running my own app too it was telling me error Pls help me out if he helped you out too

      Delete
  25. 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
  26. With the comfort of the web today, enterprise and private paperwork are additionally being stored as information within the onerous drive and archived electronically. With this, changing phrase information to PDF or transportable doc format has turn out to be well-liked as properly. If you want to learn more about this topic please visit onlineconvertfree

    ReplyDelete
  27. A 43% 2:28 p.m. KB/s 1. ERROR in /storage/emulated/0/.sketchware/mysc/ 606/app/src/main/java/com/my/newproject6/ MainActivity.java (at line 120) hasCameraFlash = getPackageManager(). hasSystemFeature(PackageManager.FEATURE_CAMER AFLASH); AAAAAAAAAAAAAA hasCameraFlash cannot be resolved to a variable 2. ERROR in /storage/emulated/0/.sketchware/mysc/ 606/app/src/main/java/com/my/newproject6/ MainActivity.java (at line 141) flashLightStatus = true; imageview1.setlmageResource(R.drawable.ic_flash_on _black); } catch (android.hardware.camera2.CameraAccessException e) {} AAAAAAAAAAAAAAAA flashLightStatus cannot be resolved to a variable 3. ERROR in /storage/emulated/0/.sketchware/mysc/ 606/app/src/main/java/com/my/newproject6/ MainActivity.java (at line 152) flashLightStatus = false; imageview1.setimageResource(R.drawable.ic_flash_of f_black); } catch (android.hardware.camera2.CameraAccessException e) {} %3! AAAAAAAAAAAAAA^A flashLightStatus cannot be resolved to a variable 3 problems (3 errors)
    How to solve

    ReplyDelete
    Replies
    1. Pls what did he tell you as the solution because after running my own app too it was telling me error Pls help me out if he helped you out too..

      Delete
  28. I Try It And Did Not work and wen i click the bulid button tall me skatsware app has been stoped

    ReplyDelete
  29. Sir I make a flesh light completed

    ReplyDelete
  30. Please Help me it says PackageManager cannot be solved as a variable

    ReplyDelete
  31. Sir, when I run this app in sketchware app it says ic_flash_on_black cannot be resolved or is not a field.
    Any suggestions???

    ReplyDelete
  32. Things to note setTorchMode() has added only in API >22 or API>=22 but what Can I use instead of that. So I have use Camera.open() but Sketchware says this method is Deprecated so I have added @Deprecated at starting of all block but still Sketchware shows error insert enum identifier to complete enum header name please help me

    ReplyDelete
  33. Sir in my mobile there is front flash light so I have to make front flash light app so what can I write there

    ReplyDelete
  34. Plz help mee show log failsd priem plese reply

    ReplyDelete
  35. This is the best blog ever keep up the good work man

    ReplyDelete
  36. Compile Error: FlashLightStatus cannot resolved to a variable

    ReplyDelete
  37. Excellent Blog! I would like to thanks for the efforts you have made in writing this post.
    I am hoping the same best work from you in the future as well. This is very beneficial to me.
    I’m happy I came across this website. I still learn something new from your posts! It will give
    you a great idea aboutAnti-Intrusion IT Services
    in Canada

    ReplyDelete
  38. Very useful information discussed using well-researched facts and figures. Keep up the good work! For more such exciting posts, do not forget to stop by our blog Web and Mobile Application Development.

    ReplyDelete
  39. I found this one pretty fascinating and it should go into my collection. Very good work! I am Impressed.
    Poker Game Development Company

    ReplyDelete
  40. I appreciate your processes listed above to create the app. But everytime I press "run", it tells me error.
    It says the error is at line 122. Duplicate local variable cameraManager

    ReplyDelete
  41. You are doing a great job by writing such an informative article. Interesting at the same time. Also check this out Baseball Field Lights. Thank you.

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

How to enable upload from webview in Sketchware?

Enable Fullscreen for Youtube videos in WebView

Creating a Drawing View in Sketchware

List of Calendar Format symbols valid in Sketchware