Page 1 of 1

Enable bright flashlight Torch (using old Camera API)

Posted: 04 Jan 2020 20:57
by emaeee
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-)

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

Posted: 07 Jan 2020 16:30
by Desmanto
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.

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

Posted: 08 Jan 2020 00:56
by anuraag

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.

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

Posted: 09 Jan 2020 18:55
by emaeee
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.

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

Posted: 09 Jan 2020 23:08
by anuraag
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

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

Posted: 10 Jan 2020 16:46
by Desmanto
@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.

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

Posted: 12 Jan 2020 18:25
by emaeee
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.

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

Posted: 12 Jan 2020 20:23
by Micky Micky
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!

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

Posted: 15 Feb 2020 02:47
by Yam
I wasn't aware that automagics torch was the lowest brightness!

Anuraag that is brilliant!

Running s9+