题
我正在做一个允许用户在服务器上搜索的应用程序。如何从快速搜索框中获取文本并发送到服务器?
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String search= intent.getStringExtra(SearchManager.QUERY);
}
字符串“搜索”是用户键入的文本吗?
P/S:对不起,我的英语不好。希望你们了解我在说什么。谢谢。
看待
Wynix
解决方案
是的,字符串“搜索”是用户搜索的字符串。
一旦拥有此信息,您可以使用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());
不隶属于 StackOverflow