How to get HTML source code from url in android?

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);
            }
        });
    }
}

Leave a Comment