How to get the html of URL in android studio using Ion library


While developing an application using android studio I have faced a problem of downloading the HTML of a URL, I were using HTTP client but  faced a problem that i can’t use this method in main thread so i needed to do it asynchronously in which I have to manage the thread with my code with all the exceptions expected. I were in real need to find a good java library to manage all of the that and i found a good java library called “Ion” that make me able to download the HTML of any URL and many other useful functions like viewing an image inside imageView by providing only the URL of the image which is cool. now lets move the coding part and how it does work!


First of all you have to open your android studio and create new empty project and we will add a button  and assign the id as “myButton” and add a txtView and assign the id as “txtResult”

2016-01-31_19-09-58Layout xml file :

now lets move to main activity java file, first we have to assign the variables of of our controls on the mainActivity class like the following

To use the Ion library you have to import it in your project, open the File menu and click on “Project Structure” then on the new window click on “app” and choose “Dependencies” from the top tabs


Now click on the plus sign on the left side of this windows to add new dependency a new menu will appear choose the first option which is “Library dependency” and search for “ion” and choose the the one from “koushikdutta” like the following  picture


Now the library is imported into our project lets move again to the MainActivity class, we will add a new ClickListener to the the button to trigger the HTML download process and inside this listener we will make use of the ion library like the following code

the final step is to add permission to our application to use the internet by editing the manifest file like the following


And that’s it, now run your application in the emulator and you will get that result:


[youtube youtubeurl=”Q7e52RGimJY” ][/youtube]





  • Is this work with a page that use Javascript to fill up with data?
    My problem is, when i try to get the source of a page(not this method) it says “Enable Javascript”
    Will i get that data if i using this library?
    Thank you for your help.

Leave a Reply

Your email address will not be published. Required fields are marked *