tags:

views:

173

answers:

2

In my searchable.xml, I have:

android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"

I get the search string returned SearchManager like so:

if (Intent.ACTION_SEARCH.equals(action)) {
  searchString = intent.getStringExtra(SearchManager.QUERY);
}

Is there any way to get from the intent whether the search string came from the keyboard, or as a result of voice search and the speech Recognizer?

I know I can put entities like:

<actionkey android:keycode="KEYCODE_SEARCH" android:queryActionMsg="search"/>
<actionkey android:keycode="KEYCODE_ENTER" android:queryActionMsg="enter"/>

in my searchable.xml file, and then use intent.getIntExtra(SearchManager.ACTION_KEY,-999) to see if the search started because the user hit the Enter key on the keyboard, or the hardware Search button, but I don't see how to detect that the search was started from the "microphone" icon button, or the "search" icon button in the search bar.

(In the case of a voice search, I need to echo the text back to the user while I do a further web lookup. For a text search, echoing what the user just typed is redundant.)

How can I tell the difference?

A: 

I'm guessing that the voice input is just an input method editor (IME), and you aren't going to be able to get any info on what IME was used to enter the text.

mbaird
No, it's not an input method.
DavidPhillipOster
Voice input is not an IME? Where do you see that information?
mbaird
Quoting from: http://developer.android.com/reference/android/app/SearchManager.html"If [launchRecognizer is] set, the voice search button will take the user directly to a built-in voice recording activity. This activity will prompt the user to speak, transcribe the spoken text, and forward the resulting query text to the searchable activity, just as if the user had typed it into the search UI and clicked the search button."http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html says "An input method (IME) is implemented as a Service..."
DavidPhillipOster
Since one is an Activity, and the other is a a Service, I assumed they were different things.
DavidPhillipOster
A: 

Answering my own question: if I just type a query, the QUERY and the USER_QUERY both return the typed text. If I speak it, the USER_QUERY is null.

DavidPhillipOster