开发者

How to have onSearchRequested not open a web browser

I have a button in my app. When it is pressed I call the onSearchRequested() method. When this is called the stock search box comes up so the user can type some junk in there. When they press "Go" I need the results returned back to my application but instead the stock browser is opened and a goog开发者_开发知识库le search is performed. How can I tell it to return the results to my application instead.

I've tried these items in my manifest.xml file:

<meta-data android:name="android.app.default_searchable"
android:value=".MainActivity" />

<activity android:name=".MainActivity"
android:launchMode="singleTop"

<intent-filter>
<action android:name="android.intent.action.SEARCH" />                         
</intent-filter>

I've also tried to capture the result in my onCreate with this:

Intent intent = getIntent();        
if (Intent.ACTION_SEARCH.equals(intent.getAction())) 


This is covered fairly well in the documentation. In particular, you are missing the searchable <meta-data> element (and, presumably, the corresponding XML file). Here is a sample project showing the use of search within an application.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜