1. Are you ready for the Galaxy S20? Here is everything we know so far!

Getting web page code with android

Discussion in 'Android Development' started by enoua, Jan 26, 2016.

  1. enoua

    enoua Lurker
    Thread Starter

    Hi everyone,

    I am new here. I came to here for searching an answer. My problem is getting html content from a website. I need to get code as a string. I tried many codes for this. My latest code is below.
    Code (Text):
    2. try
    3. {
    5.     URL url = new URL(myURL);
    6.     BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    7.     String str;
    8.     String cumle = "";
    9.     while ((str = in.readLine()) != null){
    10.            cumle += str;
    11.     }
    12.     twicerik.setText(cumle);
    13.     in.close();
    14. }
    15. catch (Exception ex)
    16. {
    17.     twicerik.setText(ex.getMessage());
    18. }
    Also i added to internet permission to manifest file
    Code (Text):
    2. <uses-permission android:name="android.permission.INTERNET" />
    twicerik is a textview.

    When I tried to run this application it writes nothing on twicerik. Also cannot catch any error on twicerik. Can anybody help me ?

    #1 enoua, Jan 26, 2016
    Last edited: Jan 28, 2016

    1. Download the Forums for Android™ app!


  2. Unforgiven

    Unforgiven ...eschew obfuscation...

    Pro tip for the forum, put your code inside code tags to make it easier for the folks that can help to read.:thumbsupdroid:

    code goes here
    and more code

    Code (Text):
    2. code goes here
    3. and more code
    enoua and Deleted User like this.
  3. Deleted User

    Deleted User Guest

    Couple of suggestions:-

    1. Try accessing myURL from a web browser. What happens?
    2. Run up your app in debug mode, set a breakpoint just before the while loop and step through the code. What happens?
    Unforgiven likes this.
  4. enoua

    enoua Lurker
    Thread Starter

    I solved this proble with using URLConnection and Inputstream in AsyncTask. Thanks for your answer. :thumbsupdroid:

Share This Page