Android Question Turn On / Off Flash Led

Pitag

Member
Licensed User
Hi to all,

I'am trying to use the flash led of the phone like a Torch. I searched the community and found some examples (listed below), but none of them work in newer phone.
To be more specific:
- Motorola XT1039, Android 5: All example works
- Sony Z5 Compact, Android 7: No Example Work
- Huawey P10 Lite, Android 8: No Example Work

https://www.b4x.com/android/forum/threads/48785/#content

https://www.b4x.com/android/forum/threads/turn-your-camera-flash-light-into-a-torch-also-with-java-code-inside-the-b4a-project.48367/#content

Someone was able to turn flash led on/off, for a non camera purpose?

As a workaround, it is possible to call the torch command (Sony and Huawey have the Torch icon, once you swipe down the notification bar) via Intent.

Hope I explained well, i'm not a b4a expert user and also my english is not so good.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
I think that you will need to use Camera or Camera2 for this. You can create a transparent activity and hide the preview panel.
 

Pitag

Member
Licensed User
Hi to all

Thank you for your reply. I will try the solutions posted and give feedback as soon as possible.
 

Pitag

Member
Licensed User
I think that you will need to use Camera or Camera2 for this. You can create a transparent activity and hide the preview panel.
I Tried to give a look at the camera2 example (the flash works in the process of taking photos), but it too complicated for my skill. I tried to modify the example to see if I was able to turn the flash led persistent on, but without success.

Hi, try if this works for you, it's written using B4A and inline java to support newer phones. It works for me on android 8.
If it works I'll post the relevant inline java code.

https://play.google.com/store/apps/details?id=it.davidev.ledflashtorch


Bye
I tried your app, and seems to work! I would appreciate if you could post the relevant code.

Thank you to all for the advice
 

DavideV

Active Member
Licensed User
I Tried to give a look at the camera2 example (the flash works in the process of taking photos), but it too complicated for my skill. I tried to modify the example to see if I was able to turn the flash led persistent on, but without success.



I tried your app, and seems to work! I would appreciate if you could post the relevant code.

Thank you to all for the advice
Hello Pitag,
as it can be useful also for other, i posted an example here:
https://www.b4x.com/android/forum/threads/torch-class.100801/

Cheers!
Davide
 
Top