I'm a total noob android studio, I've been doing a little project with the flashLight and with the switch button and create a voice button and say " turn on the flash light " then the light will turn on, same thing as turn it off, I already create the flash light button to turn it on and off, but I do not know how to add the command method to it, I did create the google command, but it doesn't work Please help. Thank You.
// this is the code I did for the flash light, I create an on/ off switch and the text will change when the light is on or off.
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
torch(isChecked);
}
});
}
private void torch(boolean isChecked) {
try {
cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
cameraID = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(cameraID,isChecked);
result = isChecked? "ON" : "OFF";
textView.setText(result);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
}
I did try the speech recognizer and google command but still doesn't work.
Please help me. Thank you.