Global search box extension - how to make browser to start when suggestion picked
I'm implementing global search box extension (sth like SearchableDictionary sample in android sdk). Everything works fine - suggestions are displayed properly. Problem is that I want browser to start when user picks a suggestion. (each suggestion is a link)
Columns of my cursor contain SearchManager.SUGGEST_COLUMN_INTENT_DATA, and I use that to pass http link. My searchable xml contains default intent action set to: android:searchSuggestIntentAction="android.intent.action.VIEW". But when user hi开发者_Go百科ts the suggestion, my application is started instead of browser. What am I missing?
Regards!You need to implement the search in the same app i.e Browser in your example. The SearchManager can only send intent to the current activity.
Btw, try to catch that intent which will be generated when the search item is selected and then open the browser from your activity.
Try to use this code. Rewrote the showResults function in the Searchable Dictionary sample code.
private void showResults(String query) {
Intent myIntent;
myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
startActivity(myIntent);
finish();
}
精彩评论