Led Flashlight on Galaxy Nexus Controllable by What API

LED Flashlight does not work on Samsung Galaxy Nexus

I had the same problem and solved it via using Surface View having 1px width and 1px height

LED Flashlight on Galaxy Nexus: app passed NULL surface

@Override

public void surfaceCreated(SurfaceHolder holder) {

try {
camera.setPreviewDisplay(holder);
} catch (Exception e) {

e.printStackTrace();
}
}
camera is
camera=Camera.open();

Turn on Camera from widget in Nexus S and Galaxy SII

There is no official android API allowing you to manipulate camera flash alone. You have to go via official camera API - and it does not formally define how to manipulate flash LED. YOu can set different modes, but camera software can ignore it at will.

So, if this works on sony it does not have to vork for other hardware. There could be (and most probably there are) some vendor specific undocumented APIs though.

Controlling Flashlight in All Android devices

The answer in below link saves my life!

The SurfaceView is essential for some devices.

LED flashlight on Galaxy Nexus controllable by what API?

android flashlight crash on galaxy nexus

First add the following permission :

<!-- Allows access to the flashlight -->
<permission android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal"
android:label="@string/permlab_flashlight"
android:description="@string/permdesc_flashlight" />

also for galaxy nexu you need to use a SurfaceView with size of 1dpx1dp to turn flashlight on. also you need to implement SurfaceHolder.Callback.

Check out this question.

Nexus S Flash torch mode not working

private Camera _camera;
protected static final String MODE_TORCH = Camera.Parameters.FLASH_MODE_TORCH;
protected static final String MODE_OFF = Camera.Parameters.FLASH_MODE_OFF;

private void initCamera(){
if(this._camera == null){
this._camera = Camera.open();
this._camera.startPreview();
}
}

private void releaseCamera(){
if(this._camera != null)
{
this._camera.stopPreview();
this._camera.release();
}

this._camera = null;
}

private void setCameraParameter(String value){
if(this._camera != null){
Camera.Parameters params = this._camera.getParameters();
params.setFlashMode(value);
this._camera.setParameters(params);
}
}

//To turn on just use:
private void turnOn(){
initCamera();
setCameraParameter(MODE_TORCH);
}

//to turn off just use:
private void turnOff(){
setCameraParameter(MODE_OFF);
}

//To release resorces use:
private void releaseResources(){
releaseCamera();
}

This will work on android 2.3. To work on android 2.3 and 4.0.3 you will have to play with surfaceView and surfaceHolder.



Related Topics



Leave a reply



Submit