2010-10-19 58 views
1

我在做一個允許用戶在服務器上搜索的應用程序。我如何從快速搜索框中獲取文本併發送到服務器?Android:收集快速搜索框結果表格互聯網

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

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

字符串「search」是用戶輸入的文本嗎?

P/S:抱歉我的英文不好。希望你們明白我在說什麼。 謝謝。

方面

Wynix

回答

1

是,字符串 「搜索」 是用戶所搜索的字符串。

一旦你有了這個,你可以使用HTTPGET對象發送到服務器的請求:

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

然後你可以從獲取HttpResponse對象分析結果:

String result = EntityUtils.toString(response.getEntity()); 
+0

感謝您的回覆。問題修復! – WynixToo 2010-11-24 09:36:04