Android Question Turn On / Off Flash Led

Pitag

Member
Licensed User
Longtime 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/t...va-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:

Pitag

Member
Licensed User
Longtime User
Hi to all

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

Pitag

Member
Licensed User
Longtime 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
 
Upvote 0

DavideV

Active Member
Licensed User
Longtime 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
 
Upvote 0
Top