Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

How to get HTML source code from url in android?

I am working on project to get html source code in a string in vb.net using dom parser to get source code of a page.

1) I want to implement the same in android, what will be the approach to get source code of webpage by calling a url in android. 2) I would be having two layouts for source code in one layout and other for the webpage itself. If i am changing title tag value in source code layout, its must be automatically updated on actual webpage ?

What would be the best approach to do that in android ?

Any kind of help will be highly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can get Html code from any URL by using ion library.

Go to the project structure, click on app, click on Dependencies, click on '+', just type ion you will see com.koushikdutta.ion:ion:2.1.8 click it and click ok. Now you can use ion library to get html code from URL.

public class HtmlCode extends Activity {
    TextView tv;

    public void onCreate(Bundle s)
    {
        super.onCreate(s);
        setContentView(R.layout.httpexample);

        tv = (TextView)findViewById(R.id.tvHttp);
        Ion.with(getApplicationContext()).load("http://www.your_URL.com").asString().setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {

                tv.setText(result);
            }
        });
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...