I have been wracking my brains but have come up short. https://developer.android.com/training/search/setup.html I am trying to figure out how to find out when the user has clicked on a voice button or for that matter what the user has said. This is independent of what the user types on a searchview. So, the https://developer.android.com/reference/android/widget/SearchView.html#setOnSearchClickListener(android.view.View.OnClickListener).. will not work.
Other than extending the SearchView and putting in my own click listener is there a way for me to find out when the user has clicked on the voice icon?
Just like any search, the result is found in SearchManager.QUERY. However, for voice search, SearchManager.USER_QUERY will be empty as per its documentation:
Intent extra data key: Use this key with content.Intent.getStringExtra() to obtain the query string typed in by the user. This may be different from the value of QUERY if the intent is the result of selecting a suggestion. In that case, QUERY will contain the value of SUGGEST_COLUMN_QUERY for the suggestion, and USER_QUERY will contain the string typed by the user.
Related
in android stuido I would like to code an activity, where the user can input numbers. For, example he types the number to the textfield, click 'OK' button, then the textfield gets clear, he types the second number, than the third, and after they give the third number the program goes to another activity and sayst thanks for the free number. I would like to save the three numbers for further use and have them in an ascending order. How should I do it?
I agree with Andrii, this is a very vague and general question. To get you pointed in the right direction though, you would want a layout with an number based-editText widget (for the user input). I would then add the button, and then implement OnClickListener for the button so that everytime the button is pressed, it calls a method you will define that will store the value in an array or list (which can be sorted), along with some kind of tracker to keep track of how many numbers have been entered - then clearing the editText field so that another number can be input; on the third number, the method calls the activity via intent or some other way saying "thanks for the free number".
This is all general and it is going to take quite a bit of work and API Guide/DeveloperDocs searching on the Android web site.
I cannot believe that I'm not seeing more discussions about this issue. Am I missing something that obvious?
I have my activity with SearchView widget with Voice enabled. This a singleTop instance, so that same activity will be able to catch the search intent.
When user inputs using voice, I would like to display the query text to the user for any correction (if needed) before the actual search happens.
In my onNewIntent() method, I handle the search intent to retrive the query text from the voice and update the search text box.
However, as soon as I set the text box with the query text, a new search intent is triggered with the SearchViews Text. And the same is received by my onNewIntent().
This is going in an infinite loop.
I tried to set up the SearchView's OnQueryTextListener, hoping the listener will catch the search text from the text box directly. It did, however, that didn't stop new search intents to be triggered.
I'm about to give up the SearchView. Considering I wanted to have the voice and suggestion features, I'm hoping someone can suggest me a solution for this problem.
Fixed.
The problem was the call to display the query text to the text box, searchView.setQuery(query, false) takes two parameters, and the second parameter indicates if the text needs to be submitted after placing in the box. I must have copied the code from an example and didn't pay attention to second parameter. It was 'true' but should be 'false' in this case.
I have implemented search dialog and online search suggestion. But I want when user click on suggestion to copy string from suggestion list to search dialog and when user click on search button to start searching. Now when user click on suggestion searching is automatic start.
Take a look at http://developer.android.com/guide/topics/search/adding-custom-suggestions.html#RewritingQueryText which lists 3 different approaches to do this as per below:
1) Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromText" value. In this case, the content from the suggestion's SUGGEST_COLUMN_TEXT_1 column is used to rewrite the query text.
2) Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromData" value. In this case, the content from the suggestion's SUGGEST_COLUMN_INTENT_DATA column is used to rewrite the query text. This should only be used with URI's or other data formats that are intended to be user-visible, such as HTTP URLs. Internal URI schemes should not be used to rewrite the query in this way.
3) Provide a unique query text string in the SUGGEST_COLUMN_QUERY column of your suggestions table. If this column is present and contains a value for the current suggestion, it is used to rewrite the query text (and override either of the previous implementations).
I have an android app which displays quotes and have navigation to go to next quote and so on. would like to add "Save Quote As favourite" based on users selection of particular quote.
Once user saves Fav quotes and wants to see those quotes only, app should show those quotes.
Currently app reads the quotes from XML file. Let me know if any more information is required to understand the problem.
I would provide every quote with an ID (int). Whenever the user selects a quote to be a favourite, that ID is saved to a Set of integers. Later on if user decides to show favourites, you fetch all quotes with your IDs from the Set and show them in a appropriate view, for example a ListView
If you have a Quote class or something like that, you might as well put them in a collection whenever user decide his favourites, and show them in a ListView with a custom adapter.
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?
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.
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.