开发者

How to aquire text from a webserver and show it depending on region

Is there a way to extract the text from a website (That only has text and can be updated by the webserver) and put it in a text view or string variable so that it will show the text in my android app.

Also, there are different languages based on what region 开发者_运维问答your phone is in (English being the default).

This is what I've been using so far

    public String getText(String uri) {
    HttpClient client1 = new DefaultHttpClient();
    HttpGet request = new HttpGet(uri);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        String response_str = client1.execute(request, responseHandler);
        return response_str;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";

    }

Unfortunately I haven't figured out a way to get rid of the html code or how to change the website being passed in depending on the region. Thanks


If the html header, body color, etc keeps a static format (such as always ending in <br>), you can use the split(...) method in the String class.


this is a very simple function that I use to make my code look cleaner.

    public String getText(String uri) {
    HttpClient client1 = new DefaultHttpClient();
    HttpGet request = new HttpGet(uri);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        String response_str = client1.execute(request, responseHandler);
        return response_str;

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";

    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜