views:

2550

answers:

4

I've been trying to make my app implement the built in quick search, similar to how it is done in ApiDemos' "app/search/invoke search". I have tried everything from trying to follow different examples, to copying the code exactly as it is in ApiDemos.

All I've found for the former have been concerned with older versions of the SDK, and simply not worked. As for the stuff that I can actually run and see working in ApiDemos, I've tried copying the following

com.example.android.apis.app.SearchInvoke.java
com.example.android.apis.app.SearchQueryResults.java
com.example.android.apis.app.SearchSuggestionSampleProvider.java

res/layout/search_invoke.xml
res/layout/search_query_results.xml
res/values/arrays.xml
res/values/strings.xml
res/xml/searchable.xml

... and everything under "Search Samples" in AndroidManifest.xml

This copying gets me a view that looks exactly like the one I'm facing when running ApiDemos, but when I click the search button, in the quick search box, Android always just opens up a browser window, with Google search results for the given query. I simply cannot find the critical component in ApiDemos that tells android that I want to use my own custom code for handling the search request.

I would really appreciate some help in this matter. Both documentation and other online resources seem very lacking when it comes to this.

Thanks.

+1  A: 

Try reading this first. If that does not help, you can try looking at the search example from one of my books -- that example integrates with the Quick Search Box, and perhaps it will give you more clues.

CommonsWare
Hi. Thanks for your comment, but neither the resources you've linked to, or the example code you've provided, seems to work for me. The search button invokes the global search ui, which is what i want, but typing anything in it only yields the default suggestions, and hitting the search button always opens up a web view. What I want is to capture the click of the search button, and generate a result view of my own. I don't even need a suggestion provider, if I can just get the search working. Surely, this should be quite doable...?
David Hedlund
No, it is not doable, short of modifying the firmware, or perhaps writing a replacement home app with a search box that behaves the way you want.
CommonsWare
Then, is this not what, say, Market is doing? Or the Search Invoke demo in ApiDemos. They are both examples of searches that appear at the click of the device's search button, and when the button is clicked in the view that appears, they generate their own result view, rather than opening a webview with regular google search results...?
David Hedlund
If one of the API Demos does what you want, grab the code for that API demo -- it is in your SDK. At least in the case of the Android Market, that's not the Quick Search Box, but rather their own search box for a local search, AFAICT.
CommonsWare
In that case I might have used the wrong terminology, and a local search might indeed be what I want. Either way, what I have not found a way to avoid is for the web view to be loaded when the search button is clicked. I have copied everything I can possibly find in the API Demos, but I still have not found the critical piece of code that lets me control the search results myself, rather than opening the browser
David Hedlund
A: 

In addition to the examples provided by commonsware.com, you can look at the Searchable Dictionary in the samples directory of the 1.6 SDK.

http://developer.android.com/guide/samples/SearchableDictionary/index.html

AshtonBRSC
A: 

I was wrong before... the SDK documentation has a thurough explanation in the docs for SearchManager that I suggest you take a look at. In addition, as CommonsWare mentioned, the blog entry is also a good resource.

fiXedd
+3  A: 

For reference, four months (and god knows how many attempts) later, I've found the part of the documentation I've missed out on, that had the whole search box behave fire up browser search results, instead of passing them to my own activity. It all comes down to a little notice found here:

Note that all user-visible strings must be provided in the form of "@string" references. Hard-coded strings, which cannot be localized, will not work properly in search metadata.

David Hedlund
Wow, thanks. That is exactly what fixed my issue -- it would not accept hard-coded string values while I was testing. I simply converted it to use refs in strings.xml and it works not.
Dustin