2012-04-30 18 views
10

¿Alguien sabe por qué la vista web muestra la página en blanco? Este es el códigoPantalla WebView en blanco o en blanco página

webView = (WebView) this.findViewById(R.id.webView); 
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl(THE_URL); 
webView.setWebViewClient(new WebViewClient()); 

y estas funciones también se llama:

@Override 
public void onPageFinished(WebView view, String url) { 
} 

Me estoy perdiendo algo allí? Por supuesto, el error no proviene del XML, porque la vista web solo no muestra alguna URL.

Gracias

+0

¿Otorgó este permiso en manifiesto? – Aerrow

+0

por supuesto ... muestra el otro html – Rendy

+0

¿Encontró la solución? –

Respuesta

1

Consulte este link. En su código, está creando dos clientes de vistas web simultáneamente.

mwebview=(WebView)findViewById(R.id.webview); 
mwebview.getSettings().setJavaScriptEnabled(true); 
mwebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 
mwebview.loadUrl(webUrl); 
mwebview.setWebChromeClient(new WebChromeClient()); 
1

En lugar de su actividad probar esto,

main.xml

<!--?xml version="1.0" encoding="utf-8"?--> 
<Linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> 

    <Textview android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="This is the demo of WebView Client" android:textsize="20sp" android:gravity="center_horizontal"> 
    </Textview> 

    <Webview android:id="@+id/webview01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1"> 
    </Webview> 

    <Imageview android:src="@drawable/ic_launcher" android:layout_height="wrap_content" android:layout_width="fill_parent">  

</Imageview></Linearlayout> 

WebViewClientDemoActivity.java

import android.app.Activity; 
    import android.graphics.Bitmap; 
    import android.os.Bundle; 
    import android.view.KeyEvent; 
    import android.webkit.WebView; 
    import android.webkit.WebViewClient; 

    /* 
    * Demo of creating an application to open any URL inside the application and clicking on any link from that URl 
    should not open Native browser but that URL should open in the same screen. 
    */ 
    public class WebViewClientDemoActivity extends Activity { 
     /** Called when the activity is first created. */ 

     WebView web; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      web = (WebView) findViewById(R.id.webview01); 
      web.setWebViewClient(new myWebClient()); 
      web.getSettings().setJavaScriptEnabled(true); 
      web.loadUrl("http://www.google.com"); 
     } 

     public class myWebClient extends WebViewClient 
     { 
      @Override 
      public void onPageStarted(WebView view, String url, Bitmap favicon) { 
       // TODO Auto-generated method stub 
       super.onPageStarted(view, url, favicon); 
      } 

      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       // TODO Auto-generated method stub 

       view.loadUrl(url); 
       return true; 

      } 
     } 

     // To handle "Back" key press event for WebView to go back to previous screen. 
     @Override 
     public boolean onKeyDown(int keyCode, KeyEvent event) 
     { 
     if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) { 
      web.goBack(); 
      return true; 
     } 
     return super.onKeyDown(keyCode, event); 
     } 
    } 

En su manifest.xml utilizan estos permisions

<uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
+0

mi código es el mismo que el tuyo en realidad – Rendy

+0

si hay algún error o advertencia en Log cat? – Aerrow

+0

no, no hay – Rendy

5

Para cualquier persona que todavía tiene este problema, parece que el WebViewClient no le avisa si una conexión segura a través de https ha fallado. Es probable que esto se deba a un error de SSL en el servidor al que se está conectando.

Puede intentar usar http en su lugar si el servidor lo permite.

+1

Gracias, esto me ayudó a resolver un problema similar. –

Cuestiones relacionadas