How can blink my flashlight app using 1 image button and using camera api 2 ?? Please someone help me.
Asked
Active
Viewed 189 times
-6
-
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 Answers
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 :
Check whether flash light is available or not ?
If yes then Turn Off/On
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
-
I have made an flashlight app using camera API 2 but I want to blink my flashlight with a Image button and and Camera API 2 since Camera ApI is deprecated. How can I blink it..please ..help me I'm so frustrated ,I don't know what to do.!! – user9042561 Dec 27 '17 at 09:50
-
-
Blinking a flashlight is nothing but turning the flashlight off and on continuously. Follow the tutorial given above and you will learn more about it. For the blinking, you can apply your own logic and set the params in it to turn it off and on again at a regular interval of time. – nimi0112 Dec 27 '17 at 09:57
-
But as a new to this programming I don't know how to write code by myself ..so that's why I'm facing problems.kindly help me to blink my flashlight ..by some code useing camera API 2 – user9042561 Dec 27 '17 at 12:03
-
-
I have used that code but android studio saying me that camera ApI is deprecated.. So what can I do now using camera API 2 – user9042561 Dec 27 '17 at 13:36
-
Please reach out to me at nimishnandwana@gmail.com, we can discuss and solve your problem there. – nimi0112 Dec 27 '17 at 13:39
-
-
-
-
-
That's what I am saying mail me at nimishnandwana@gmail.com, we can continue this discussion further. – nimi0112 Dec 28 '17 at 00:43
-