谷歌搜索Android

时间:2014-05-14 20:21:03

标签: android search google-search android-searchmanager

我想在我的应用中添加一个简单的Google搜索。我找到了这段代码,但这并不是我要搜索的内容。搜索下方来自给定网址。

String url = "http://www.google.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); 

问题是我希望从用户那里获取搜索文本,如果可能的话,无需启动像这样的新活动:

Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editTextInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);

1 个答案:

答案 0 :(得分:2)

从用户处获取文本并将其放在URI中,然后启动意图。

String url = "http://www.google.com/search?q=" + userText;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);