Enable bright flashlight Torch (using old Camera API)

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
emaeee
Posts: 19
Joined: 10 Nov 2017 22:37

Enable bright flashlight Torch (using old Camera API)

Post by emaeee » 04 Jan 2020 20:57

Hello,
on my Samsung Galaxy S10 I can choose the torch brightness using the quick setting toggle provided by Samsung ( https://www.samsung.com/ae/support/mobi ... brightness ).
Unfortunately, using "flashlight" action in Automagic (and in most of the apps) enables the minimun brightness torch, and, unfortunately again, i don't think there's a simple way to replicate the action performed by the quick toggle (even on rooted devices like mine, but I'll take suggestions).
Some apps (most of old apps) though, are able to toggle the brightest torch mode. Digging a bit into the topic let me discover that these old apps still use the old camera API (still supported by many firmwares), and using methods like:
Camera.Parameters.getSupportedFlashModes
Camera.Parameters.setFlashMode
Camera.startPreview()
release()

they can switch ON and OFF the brightest torch mode from camera.

Here's 3 examples of really simple apps that can toggle this mode:
https://play.google.com/store/apps/deta ... l&hl=en_US
https://play.google.com/store/apps/deta ... h&hl=en_US
https://play.google.com/store/apps/deta ... y&hl=en_US

Martin, when you have some time, could you please add an action to enable/disable powerful torch mode using the old Camera API ?

Ps. Moved from MM to Pie, and still enjoying my Automagic mate 8-)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Enable bright flashlight Torch (using old Camera API)

Post by Desmanto » 07 Jan 2020 16:30

This maybe can be done using calljavamethod(). But as I try that, I got error of unsupported something. Maybe because mine is camera2 API all the level. But it should still support old API for compatibility. Maybe anuraag can help you with this.

If the calljavamethod works, there will be a higher chance that Martin will include this feature somewhere in the future.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Enable bright flashlight Torch (using old Camera API)

Post by anuraag » 08 Jan 2020 00:56

Code: Select all

camera = callJavaStaticMethod("android.hardware.Camera", "open()");
parameters = callJavaMethod(camera, "android.hardware.Camera", "getParameters()");
flashModes = callJavaMethod(parameters, "android.hardware.Camera$Parameters", "getSupportedFlashModes()");
flashOnParameter = null;
if (containsElement(flashModes, "torch")) {flashOnParameter = "torch"}
else if (containsElement(flashModes, "on")) {flashOnParameter = "on"}
else if (containsElement(flashModes, "auto")) {flashOnParameter = "auto"}
callJavaMethod(parameters, "android.hardware.Camera$Parameters", "setFlashMode(java.lang.String)", flashOnParameter);
callJavaMethod(camera, "android.hardware.Camera", "setParameters(android.hardware.Camera$Parameters)", parameters);
callJavaMethod(camera, "android.hardware.Camera", "setPreviewTexture(android.graphics.SurfaceTexture)", callJavaConstructor("android.graphics.SurfaceTexture", "SurfaceTexture(int)", 0));
callJavaMethod(camera, "android.hardware.Camera", "startPreview()");

sleep("10s");

callJavaMethod(camera, "android.hardware.Camera", "stopPreview()");
callJavaMethod(camera, "android.hardware.Camera", "release()");
camera=null
Try this.

Edit: on my Samsung a7(2017) Automagic's built-in action turns full flashlight by default. And above code doesn't work well in my device.
Last edited by anuraag on 10 Jan 2020 23:31, edited 1 time in total.

emaeee
Posts: 19
Joined: 10 Nov 2017 22:37

Re: Enable bright flashlight Torch (using old Camera API)

Post by emaeee » 09 Jan 2020 18:55

Desmanto wrote:
07 Jan 2020 16:30
This maybe can be done using calljavamethod(). But as I try that, I got error of unsupported something. Maybe because mine is camera2 API all the level. But it should still support old API for compatibility. Maybe anuraag can help you with this.

If the calljavamethod works, there will be a higher chance that Martin will include this feature somewhere in the future.
Thanks for the suggestion Desmanto, infact the script from anuraag:
anuraag wrote:
08 Jan 2020 00:56
.....
Try this.

Edit: on my Samsung a7(2017) Automagic's built-in action turns full flashlight by default. And above code doesn't work well in my device.
Works brilliantly, thanks a lot mate!!!

I'm sharing a flow with trigger: Shortcut that will activate and deactivate alternatively the brighter torch (using deprecated Camera API) and also will turn off torch after 10 minutes.
This might work also on other devices like Sony Xperia ones (my Z5c used to have different flashlight powers for torch apps and for camera flash but also got quite hot with full power flash on :lol:)

Thanks guys for the support.

ps: i have another request directly for Martin: add Condition: service running and Condition: process running for rooted devices > Nougat. I had to search the web to find the right root commands for the purpose and had to refine the flows to apply the condition correctly.
Attachments
flow_Brighter_Torch_camera_API_20200109_192312.zip
(1.41 KiB) Downloaded 1227 times

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Enable bright flashlight Torch (using old Camera API)

Post by anuraag » 09 Jan 2020 23:08

Glad it works.
It will be better if you use global Variable instead of opening camera 2 times. Here is modified flow.
http://automagic4android.com/flow.php?i ... 50ba37e3f5

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Enable bright flashlight Torch (using old Camera API)

Post by Desmanto » 10 Jan 2020 16:46

@emaeee : Glad it works. Hopefully it will be added in the next EAP version. But no this AM 1.38, because adding new feature require longer testing. I just wish AM 1.38 released as stable ASAP, as it contains the new read log permission which open the door of more possibilities to many non-root users.

@anuraag : Thanks for the java, as usual, it is working perfectly. Mine don't have the strong flash, but the code still can toggle properly. Which mean your code can be implemented as built-in action without interferring with other devices.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

emaeee
Posts: 19
Joined: 10 Nov 2017 22:37

Re: Enable bright flashlight Torch (using old Camera API)

Post by emaeee » 12 Jan 2020 18:25

anuraag wrote:
09 Jan 2020 23:08
Glad it works.
It will be better if you use global Variable instead of opening camera 2 times. Here is modified flow.
http://automagic4android.com/flow.php?i ... 50ba37e3f5
Thanks for the suggestion and for the share.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Enable bright flashlight Torch (using old Camera API)

Post by Micky Micky » 12 Jan 2020 20:23

I didn't know about the hidden menus, nor the brightness levels for the torch.
It works on my S10 running Android 10.

Many thanks all round!
Crude but it works.

User avatar
Yam
Posts: 54
Joined: 23 Nov 2019 09:07

Re: Enable bright flashlight Torch (using old Camera API)

Post by Yam » 15 Feb 2020 02:47

I wasn't aware that automagics torch was the lowest brightness!

Anuraag that is brilliant!

Running s9+
Every life altering decision you have made, has lead to you reading this.

Locked