Android phone flashlight ON/OFF
I would like to ON and OFF the flashlight of the android phone by toggling a button.
I do so. But when I turn ON the flashlight the app do not response. Does Maxst support it or it has other solution?
(I work on unity3d)
Maxst AR SDK doesn't directly affect the flashlight functionality. We're afraid the information you gave us is not enough for us to figure out why.
If you send us some more detailed material regarding this issue such as the event log at the time you call the code or the sample code itself, we can check for you.
Here is the code I used.
private bool Active;
private AndroidJavaObject camera1;
void FL_Start()
{
AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera");
WebCamDevice[] devices = WebCamTexture.devices;
int camID = 0;
camera1 = cameraClass.CallStatic<AndroidJavaObject>("open", camID);
if (camera1 != null)
{
AndroidJavaObject cameraParameters = camera1.Call<AndroidJavaObject>("getParameters");
cameraParameters.Call("setFlashMode", "torch");
camera1.Call("setParameters", cameraParameters);
Active = true;
}
else
{
Debug.LogError("[CameraParametersAndroid] Camera not available");
}
}
void OnDestroy()
{
FL_Stop();
}
void FL_Stop()
{
if (camera1 != null)
{
camera1.Call("stopPreview");
camera1.Call("release");
Active = false;
}
else
{
Debug.LogError("[CameraParametersAndroid] Camera not available");
}
}
void OnGUI()
{
GUILayout.BeginArea(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.3f, Screen.height * 0.1f));
if (!Active)
{
if (GUILayout.Button("ENABLE FLASHLIGHT"))
FL_Start();
}
else
{
if (GUILayout.Button("DISABLE FLASHLIGHT"))
FL_Stop();
}
GUILayout.EndArea();
}