I want to turn on front flash light (not with camera preview) programmatically in Android. I googled for it but the help i found referred me to this page
Does anyo
There's different ways to access Camera Flash in different Android versions. Few APIs stopped working in Lollipop and then it got changed again in Marshmallow. To overcome this, I have created a simple library that I have been using in few of my projects and it's giving good results. It's still incomplete, but you can try to check the code and find the missing pieces. Here's the link - NoobCameraFlash.
If you just want to integrate in your code, you can use gradle for that. Here's the instructions (Taken directly from the Readme) -
Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.Abhi347:NoobCameraFlash:0.0.1'
}
Initialize the NoobCameraManager
singleton.
NoobCameraManager.getInstance().init(this);
You can optionally set the Log Level for debug logging. Logging uses LumberJack library. The default LogLevel is LogLevel.None
NoobCameraManager.getInstance().init(this, LogLevel.Verbose);
After that you just need to call the singleton to turn on or off the camera flash.
NoobCameraManager.getInstance().turnOnFlash();
NoobCameraManager.getInstance().turnOffFlash();
You have to take care of the runtime permissions to access Camera yourself, before initializing the NoobCameraManager. In version 0.1.2 or earlier we used to provide support for permissions directly from the library, but due to dependency on the Activity object, we have to remove it.
It's easy to toggle Flash too
if(NoobCameraManager.getInstance().isFlashOn()){
NoobCameraManager.getInstance().turnOffFlash();
}else{
NoobCameraManager.getInstance().turnOnFlash();
}