Data from a website in Android app
<p>I am making a semester project on Android in which I am using Data from a website.</p>

<p>I have found a java code to get the web source code, but that does not work in android application.</p>

<p>I have added permissions in manifest files for internet.</p>

<p>The app should be such that on clicking a button a toast will tell whether website data has been accessed or not.</p>

<pre><code>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class WebData
{
public static void main(String[] args) throws Exception{
    URL url = new URL("http://www.oracle.com/");
    BufferedReader reader = null;
    StringBuilder builder = new StringBuilder();
    try {
        reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
        for (String line; (line = reader.readLine()) != null;) {
            builder.append(line.trim());
        }
    } finally {
        if (reader != null) {
            try { reader.close(); } catch (IOException logOrIgnore) {
              System.out.println("Data Accessing Problem");
                     }
        }
    }

    }
} 
</code></pre>
