2013-04-30 2 views
0

간단한 응용 프로그램이있어서 google.com을 표시 할 WebView를 만들 수 없습니다.WebView가 인터넷 권한과 함께 작동하지 않습니다.

EditText에는 오류는 표시되지 않지만 아무 것도 표시되지 않습니다.

인터넷 권한이 이미 추가되었지만 작동하지 않습니다.

이것은 내 매니페스트입니다.

<?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> 

매니 페스트에는 문제가 없다고 생각합니다. 문제가 정확히 무엇인지 모르겠습니다. 이것은 내 코드입니다.

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(); 
    } 

LogCat에 오류 또는 메시지가 없습니다. 내 장치에서이 코드를 테스트하고 있습니다.

+1

'WebView'가 없습니다. – CommonsWare

+0

무엇을 시도 했습니까? 예를 들어 디버깅을 시도하고 코드를 진행하면서 어떤 일이 발생했는지 확인하십시오. 실행중인 코드 줄과 프로세스의 다른 단계에서 얻는 결과의 종류를 확인하기 위해 로그 문을 추가하려 했습니까? –

+0

url을 webview에 표시하고 싶습니다.? – Raghunandan

답변

0

메인 스레드에서 네트워크에 액세스하면 안됩니다. AsyncTask를 사용하여 액세스를 수행하십시오.

관련 문제