简体   繁体   English

WebView显示空白页

[英]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/ ) 编辑-使用其他URL( http://www.globo.com/

Code: Activity.java 代码: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 代码: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. 但是当你运行的实际device..it同样不会让你的系统AP以及该stream_simple.html文件,该文件是在您的系统。 thats y webview showing the blank page. 多数民众赞成y webview显示空白页。

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. stream_simple.html文件放入您的android项目的assests文件夹中,然后将其加载到webview中,将为您提供所需的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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