There is a component EditText . I would like by some gesture to translate the keyboard into the input by voice. Is it possible?
- Gesture is understood as, say, a long press on the EditText field. - Einwtien
- it is already embedded in editText. no more tricks to do with it. - Borisov Max
- Customer Can't Hit Microphone Icon - Einwtien
- Another option is to click on the menu item, and the focus went to editText and the keyboard went into voice input mode - Einwtien
|
1 answer
You need to process your gesture and call external intent:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); theoretically it may not be in the system, so you first need to check its availability
PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities( new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() == 0) //нет распознавателя //blah-blah If there is a call to the Recognizer's startActivityForResult(intent, SPEECH_REQUEST) via startActivityForResult(intent, SPEECH_REQUEST) and in onActivityResult() the data should be put into EditText :
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SPEECH_REQUEST && resultCode == RESULT_OK) { //массив распознанных строк ArrayList<String> matches = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); //ложим в EditText } super.onActivityResult(requestCode, resultCode, data); } Update
Actually the answer to the question itself:
translate keyboard into voice input. Is it possible?
Alas, this is impossible. There is no such INPUT_TYPE , each implementation of the keyboard implements the voice input support itself.
|