开发者

What is the proper syntax to execute a google web search from my Android 2.2 application?

Working on an Android application, which needs to execute a google web search from within a ListView activity and display the results in that List View.

Such search would always be for the sam开发者_Python百科e "static" subject, such as "...bowling alleys in Chicago...", so, the user will not be entering any search criteria.

What is the proper way to accomplish this, please?


I would just URL-encode the search request, create an URL using the official Google Search API and open this in a browser, which would be:

try {
    String search = "your search here";
    String encodedSearch = URLEncoder.encode(search, "UTF-8");
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/search?q=" + encodedSearch)));
} catch (UnsupportedEncodingException e) {
    // should not happen, maybe add some Log.e() here
}

Have fun! :-)

EDIT: Oh, I just answered too quickly and now I read that you want to display the search results in a ListView. So basically you will need an API key then and use the official search API by Google. More information and documentation here: http://code.google.com/intl/de/apis/customsearch/v1/overview.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜