我是AndroidO编程中的新手StackOverFlow和初学者。我正在开发一个应用程序,通过Android手机控制LED在arduino和蓝牙适配器的帮助下,它工作正常。但现在我正在尝试添加语音识别功能,但每次使用该功能时应用程序都会崩溃。以下是我用于接收语音输入的代码。请建议任何更正:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_SPEECH && resultCode == RESULT_OK) {
String check = data
.getStringExtra(RecognizerIntent.EXTRA_RESULTS);
toastIt("What you said",check); //Just for toast messages
checkThatvoice(check);
}
}
private void checkThatvoice(String check) {
if (check.equals("Bulb 1 on")) {
sendData("1");//Sends 1 to the function for further use, it works fine
}
}