Android Example Turn your camera flash light into a torch - also with Java code inside the B4A project

See attached project. I have created this simple torch (on / off) by making use of java code found on the web and compiling it with Simple Library Compiler. Library files inside the /files folder. Copy it to you additional library folder (fiddleAround.jar and FiddleAround.xml) and refresh libs --> select/enable FiddleAround in the libs tab

EDIT: JHSTORCH_v1.zip should hopefully address the issues raised in the posts below. Copy / replace fiddleAround.jar and fiddleAround.xml to/in your additional library folder. (23)

EDIT: JHSTORCH_v2.zip - just tidied up the buttons a bit. The library files are in the /files folder of the project.

You can also try this. It is a torch but also includes the ability to generate Morse codes via the camera flash.
 

Attachments

  • JHSTORCH_v1.zip
    23.3 KB · Views: 1,099
  • JHSTORCH_v2.zip
    117.3 KB · Views: 1,588
Last edited:

dragonguy

Active Member
Licensed User
Longtime User
i found the solution, i share here
B4X:
NativeMe.RunMethod("blink",Array(50,50,10))

B4X:
public void blink (int onValue,int offValue,int flashTime){
    m_Camera = Camera.open();
    cameraParameters = m_Camera.getParameters();
   
    for (int i = 0; i <= flashTime; i++) {
        cameraParameters.setFlashMode(Parameters.FLASH_MODE_ON);
        cameraParameters.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
        cameraParameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
        m_Camera.setParameters(cameraParameters);
        m_Camera.startPreview();
        try{
            Thread.sleep(onValue);
            }catch(InterruptedException e){
                e.printStackTrace();
                }
        cameraParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
        m_Camera.setParameters(cameraParameters);
        m_Camera.stopPreview();
        try{
            Thread.sleep(offValue);
            }catch(InterruptedException e){
                e.printStackTrace();
                }
    }
    m_Camera.stopPreview();
    m_Camera.release();
    m_Camera = null;
}
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello to all
I'm trying to use your library with an app that uses cameraex. When I turn on the torch, the image display is blocked and does not resume even if I turn off the torch.

Am I wrong about something or are they incompatible?
 

mahyara

Member
Hi I'm very novice so this maybe very ridiculous I have installed this file but it does not turn on flash neither in Morse mode nor in Torch mode, the logger write dih dah ... and the vibration works perfect. I have this problem with a Sony XPERIA XZ and I have downloaded several torch and stroboscope apps from play store but some of them work and others do not turn on the flash and unfortunately none of the libraries and projects here which try to turn on the flash cannot turn on my phones flash. do you know what maybe the problem?
 
Top