Search code examples
androidstringurluricall

Confused about get string from url


i get confused about get string from url. I want use that content from web and then parse uri to make a call. I used this code with no error but not work. What I need to make it work? Will I use JSON method? Please help me. Thanks.

MainActivity.java

    Balance hehe = new Balance(); // Call the Class

    hehe.Run("http://underwear.host56.com/upload/balance.html");

    String number = hehe.getOutput();

    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + Uri.encode(number + "#")));
    startActivity(callIntent);

Balance.java

public class Balance {
    private String output;
     private String url;

     public Balance()
     {
      output = "";
     }

     public String getOutput()
     {
      return output;
     }

     public void Run(String u)
     {
        url = u;
        Thread t =  new Thread() {

           public void run() {

                   URL textUrl;
                   try {

                    textUrl = new URL(url);

                    BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));

                    String StringBuffer;
                    String stringText = "";
                    while ((StringBuffer = bufferReader.readLine()) != null) {
                       stringText += StringBuffer;
                    }
                    bufferReader.close();

                    output = stringText;

                   } catch (Exception e) {
                    // TODO Auto-generated catch block
                    //e.printStackTrace();

                    output= e.toString();
                   }

                 }
               };

               t.start();
          try {
       t.join();
      } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }

   }
}

Solution

  • In what way is it not working? The code looks roughly correct... one thing that may be giving you problems is that it appears like your hosting provider is appending some other code to the web page for you, going to that URL in a browser and viewing source shows:

    123*4*1
    <!-- Hosting24 Analytics Code -->
    <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
    <!-- End Of Analytics Code -->