0

I have a simple application and I cannot make the WebView to show google.com.

No errors but nothing show on EditText.

I has added Internet permission already but, it is not work.

This is my Manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taxihelperforcustomer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.taxihelperforcustomer.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

I think there isn't problem in manifest. I don't know what the problem is exactly. This is my code.

EditText mResult;
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mResult = (EditText)findViewById(R.id.result);

        Button btn = (Button)findViewById(R.id.sendBtn);
        btn.setOnClickListener(new Button.OnClickListener(){

   public void onClick(View v) {
    // TODO Auto-generated method stub

    String html = DownloadHtml("http://www.google.com");
    try{

     mResult.setText(html);

    } catch(HTMLException e) {
     Toast.makeText(v.getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
   }
        });
    }

public String DownloadHtml(String addr){
   StringBuilder googleHtml = new StringBuilder();
   try{
      URL url = new URL(addr);
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      if(conn != null){
         conn.setConnectTimeout(10000);
         conn.setUseCaches(false);
         if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "EUC-KR"));
            for(;;)
            {
                String line = br.readLine();
                if(line == null)
                    break;
                googleHtml.append(line + "\n");
             }
          br.close();
       }
        conn.disconnect();
     }
   } catch(Exception ex){
      Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
   }
   return googleHtml.toString();
   }

No errors or messages on the LogCat. I'm testing this code on my device.

  • 1
    You do not have a `WebView`. – CommonsWare Apr 30 '13 at 18:53
  • What have you tried? For example, have you tried debugging and see what happens as you progress through the code? have you tried adding log statements to see what lines of code are being executed and what kind of results you are getting at different steps of the process? – Scott W Apr 30 '13 at 18:53
  • You want to display url in webview.? – Raghunandan Apr 30 '13 at 18:59
  • http://stackoverflow.com/questions/16152491/enable-back-button-in-webview/16152530#16152530. Check the edit 2 in the link for webview loading a url – Raghunandan Apr 30 '13 at 19:39
  • Sorry. My question is wrong. not webview, just want to read all words on client when I access to specific url like www.google.com. – user2337081 May 01 '13 at 03:04

1 Answers1

0

You should not access the network from main thread. Use an AsyncTask to perform the access.

Scott W
  • 9,742
  • 2
  • 38
  • 53
eltabo
  • 3,749
  • 1
  • 21
  • 33