1

我正在做一个允许用户在服务器上搜索的应用程序。如何从快速搜索框中获取文本并发送到服务器?

if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

     String search= intent.getStringExtra(SearchManager.QUERY);
}

字符串“搜索”是用户输入的文本吗?

P/S:对不起我的英语不好。希望你们明白我在说什么。谢谢。

看待

威力士

4

1 回答 1

1

是的,字符串“搜索”是用户搜索过的字符串。

一旦你有了这个,你可以使用 HttpGet-object 向你的服务器发送一个请求:

HttpGet get = new HttpGet("http://yourserver.com" + search);
HttpResponse response = null;
try {
  response = client.execute(get);
}
catch (IOException e) {}
catch (ClientProtocolException e) {}

然后您可以解析来自 HttpResponse-object 的结果:

String result = EntityUtils.toString(response.getEntity());
于 2010-11-24T08:38:33.360 回答