How to navigate user to "Searchable Items" setting?
I'm planning to write an application that would provide results in quick search box.
Is there any way to fire an Intent to navigate user to "Searchable items" screen in An开发者_如何学Pythondroid 1.6?
Warning: undocumented behavior, dragons ahead!
One solution that I have found is to launch the search settings activity, like this:
final Intent searchSettings = new Intent("android.search.action.SEARCH_SETTINGS");
startActivity(searchSettings);
You can tell the user to select "searchable items" and then enable your app in there. I've tested this on Android 2.3.3 and 4.0, feel free to test on more versions and post the results here :).
Because this is undocumented you should take all possible precautions. One simple precaution is just catching the ActivityNotFoundException
that is thrown if the intent is not resolved and letting the user know the feature is unavailable. However, a better solution is outlined here.
Edit: this is actually documented. You can find that action in SearchManager.INTENT_ACTION_SEARCH_SETTINGS
, so the code above should be written as:
final Intent searchSettings = new Intent("SearchManager.INTENT_ACTION_SEARCH_SETTINGS");
startActivity(searchSettings);
You can use Java reflection to test whether SearchManager
has a static member called INTENT_ACTION_SEARCH_SETTINGS
and configure your UI accordingly. This member was added in API Level 8 (Android 2.2 Froyo), so it will not work on anything below that.
Unfortunately, there's no Intent
(that I can find) that would take the user directly to the "searchable items" settings page.
There is not an intent for this on the developer doc. I think you are going to have to dig into source.
Then you'll also have to consider the repercussions of the fact if you do find an intent, it might not be standard across all phones.
I would ask yourself if you really need it though. Search is pretty powerful in Android, and you should be able to come up with your own "search these areas" preference activity (like the one you've shown) that would do the same thing...assuming that is what your intent here is.
I'd like to improve Felix`s answer, so.. Actually, you can take user directly to "searchable items" settings page using the following:
Intent searchSettings = new Intent("com.android.quicksearchbox.action.SEARCHABLE_ITEMS");
startActivity(searchSettings);
But I had a strange behavior on my device - package names were displayed instead of app`s names.
精彩评论