简体   繁体   中英

WebView showing blank page

I'm working on a project and i need to show a webpage. But when i try to show it on a device, I get a blank page. If i copy this page and past into the device's browser, i can see it normally. Also, if I run it on a virtual device, i can see the page normally as well on both application and browser. So my problem is at the device. I already have the Internet permission.

EDIT - Worked with another URL( http://www.globo.com/ )

Code: Activity.java

    webcam = (WebView) findViewById(R.id.webcam);
    webcam.getSettings().setJavaScriptEnabled(true);
    webcam.getSettings().setBuiltInZoomControls(true);
    webcam.getSettings().setSupportZoom(true);
    webcam.setWebViewClient(new MyBrowser());

    private class MyBrowser extends WebViewClient {
         @Override
         public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;
         }
    }

    public void abrirurl(View view) {
         webcam.loadUrl("http://192.168.0.103:8080/stream_simple.html");
    }

Code: webcam.xml

 <WebView
    android:id="@+id/webcam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginBottom="50dp"
    android:layout_marginTop="15dp"
    android:layout_below="@+id/textView1" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_centerHorizontal="true"
    android:drawableLeft="@drawable/cam1"
    android:text="@string/webcam"
    android:onClick="abrirurl" />

Because in the url

http://192.168.0.103:8080    //is your system ip

and

stream_simple.html  // is your file which is in your system only.

when you run it on virtual device,which is in your system only will access the same file from system. but when you run the same on the real device..it will not get your system ap as well this stream_simple.html file,which is in your system. thats y webview showing the blank page.

solution

put stream_simple.html file in assests folder of your android project.and then load it in webview will give you the desired output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM