I'm doing an application to detect words through the camera with the api google vision and I would like to know how to turn on the flash while in the application.
here I leave the main activity code where the camera instance and the permissions are created ...
I followed the tutorial of link
protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main);
cameraView = (SurfaceView) findViewById(R.id.surface_view);
textView = (TextView) findViewById(R.id.text_view);
textView.setText("\nDetectando...");
btnDefinicion = (Button) findViewById(R.id.verDefinicion);
btnSugerencias = (Button) findViewById(R.id.verSugerencias);
btnDefinicion.setEnabled(false);
btnSugerencias.setEnabled(false);
//flash-----------------------------
//flash---------------------------
TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
if (!textRecognizer.isOperational()) {
Log.w("MainActivity", "No dependencias listas");
} else {
cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1900, 1080)
//.setRequestedPreviewSize(240, 160)
.setRequestedFps(2.0f)
.setAutoFocusEnabled(true)
.build();
cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CAMERA},
RequestCameraPermissionID);
return;
}
cameraSource.start(cameraView.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
cameraSource.stop();
}
});
textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
@Override
public void release() {
}
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
final SparseArray<TextBlock> items = detections.getDetectedItems();
if(items.size() !=0){
textView.post(new Runnable() {
@Override
public void run() {
StringBuilder stringBuilder = new StringBuilder();
TextBlock item = items.valueAt(0);
stringBuilder.append(item.getValue());
//stringBuilder.append("\n");
String bloquesPalabras = stringBuilder.toString();
procesarBloques(bloquesPalabras);
//textView.setText("Se encontró:"+"\n"+devolverPalabra(stringpalabra));
}
});
}
}
});
}
}