-6

How can blink my flashlight app using 1 image button and using camera api 2 ?? Please someone help me.

  • Your question may be blocked soon. As a word of advice, try searching the internet for code samples and if you have problems understanding, then you can ask for help here – Clement Osei Tano Dec 27 '17 at 09:29
  • I'm new to the development sir.so if u help me that would be great lesson for me.I could not get any answer about blinking my answer in the internet.. – user9042561 Dec 27 '17 at 09:31
  • Hello sir how can I learn coding by myself then I won't ask u ..if u think I have disturbed u – user9042561 Dec 27 '17 at 16:35

1 Answers1

0

Follow this link to learn about making flashlight android app.

To make the flashlight blink you can set up your own logic to turn it on and off programmatically.

Edit posting code as asked:

For this you should do like :

  1. Check whether flash light is available or not ?

  2. If yes then Turn Off/On

  3. If no then you can do whatever according to your app. needs

For Checking availability of flash in device:

You can use the following

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

which will return true if a flash is available, false if not.

Taking code from here:

private void BlinkFlash(){
    String myString = "010101010101";
    long blinkDelay =50; //Delay in ms
    for (int i = 0; i < myString.length(); i++) {
        if (myString.charAt(i) == '0') {
            params = camera.getParameters();
            params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            camera.setParameters(params);
            camera.startPreview();
            isFlashOn = true;



        } else {
            params = camera.getParameters();
            params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
            camera.setParameters(params);
            camera.stopPreview();
            isFlashOn = false;

        }
        try {
            Thread.sleep(blinkDelay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

To call this method:

yourbuttonname.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        BlinkFlash();
    }
});

Hope this helps.

nimi0112
  • 2,065
  • 1
  • 18
  • 32