Reputation: 1411
i want to on and off LED or flash of android phone programmatically but in Samsung Google nexus the flash is not on. i use many methods for it but can't get good result.
Camera mycam = Camera.open();
Parameters p = mycam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
mycam.setParameters(p);
i use these codes and also give all permission but the problem is same that it not work on Samsung google nexus.
Upvotes: 0
Views: 778
Reputation: 2885
You can try this one , it's may help you :
private void flashOn() {
camera = Camera.open();
Parameters params = camera.getParameters();
// Build.MODEL.equals("GT-P1000")
if (Build.MANUFACTURER.equalsIgnoreCase("SAMSUNG")
|| Build.MANUFACTURER.equalsIgnoreCase("LG"))
params.setFlashMode(Parameters.FLASH_MODE_ON);
else
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
camera.autoFocus(new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
}
});
}
private void flashOff() {
if (camera != null) {
camera.stopPreview();
camera.release();
}
}
and add this in your manifest file :
<permission
android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
Upvotes: 0