你可以试试这个,它可能对你有帮助:
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();
}
}
并将其添加到您的清单文件中:
<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" />