I have a problem with a flashlight app Android 4.0.4 Nexus S i9020. I have tried dozens of suggestions posted here on stackoverflow but nothing worked for me. The app worked with Android version 2.3.6 but since 4.0.4 the torch has stopped working.
Here is my impl and the logcat output.
@Override
protected void onResume()
{
super.onResume();
_Camera = Camera.open();
}
@Override
protected void onPause()
{
if (_Camera != null)
{
_Camera.release();
}
}
//called within runnable and post to a handler
private void processOffClick()
{
if (_Camera != null)
{
Parameters params = _Camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
_Camera.setParameters(params);
_Camera.stopPreview();
}
}
//called within runnable and post to a handler
private void processOnClick()
{
if (_Camera != null)
{
Parameters params = _Camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
_Camera.setParameters(params);
_Camera.startPreview();
}
}
I have also tried to execute the onclick offclick methods without runnables.
In Logcat the folling error occurs after onclick is performed.
04-07 14:10:02.719: E/CameraHardwareSec(82): preview window is NULL!
04-07 14:10:02.719: I/CameraHardwareSec(82): virtual android::status_t android::CameraHardwareSec::startPreview() : deferring
There are some camera apps in the market which work with my phone. So there must be some way to get the flashlight on.
I also tried to add an SurfaceView/Holder but it did not work. Maybe I did something wrong.
Cheers Karim