Loading...
Logo
Processing Forum
Hi all.

I'm learning coding and specialy Processing (2.0b8). For my first Android App, I need to execute the phone flashlight (i9100).

I thought Ketai librarie was the solution but the phone flash don't agree with me.

I try something like that (mainly cut/paste from ketai page):
Copy code
  1. import ketai.camera.*;
  2. KetaiCamera cam
Then, in setup
Copy code
  1.   cam = new KetaiCamera(this, 320, 240, 24);
Then, in draw :
Copy code
  1.   if (ZoneFlash()) {
  2.     FlashOnOff = ! FlashOnOff;
  3.     if (cam.isFlashEnabled()) {
  4.       cam.disableFlash();
  5.     } else {
  6.       cam.enableFlash();
  7.     }
  8.   }
Edit (30/04/2013) :

This code doesn't works when I Ioad the app for the first time but works if I press the Home phone button then reload the app. If I do the same (Home button then app), there is a crash !

How can this happen ? Exit and reload make flashlight work ! But it works only one time ...

Thanks for your help.

Replies(4)

does this code code works for you ? touch the screen to toggle on/off the torch. it works for me.
Copy code
  1. import ketai.camera.*;
    KetaiCamera cam;
    void setup()
    {
      cam = new KetaiCamera(this, 320, 240, 24);
      cam.start();
    }
    void draw()
    {
      background(0);
      if (cam !=null)
        image(cam, 0, 0);
    }

    void onCameraPreviewEvent()
    {
      cam.read();
    }

    void mousePressed()
    {

      if (cam.isFlashEnabled())
        cam.disableFlash();
      else
        cam.enableFlash();
    }


Hi Pauline,

Thanks a lot for your help. I just saw your reply (I tought I would receive a email in case of reply...) and test your code today.

Unfortunately, here is the result for my device :

debug:
Failed to open camera for camera ID: 0:Fail to connect to camera service


have you authorized camera in your sketch manifest ? (see sketch permission menu)

It works fine !

I only authorised flashlight unless camera.
You're right, this sketch needs camera but no flashlight authorization.

Thanks again for your efficient help.