开发者

Global search box extension - how to make browser to start when suggestion picked

开发者 https://www.devze.com 2022-12-22 09:06 出处:网络
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

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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号