簡體   English   中英

WebView顯示空白頁

[英]WebView showing blank page

我正在做一個項目,我需要顯示一個網頁。 但是,當我嘗試在設備上顯示它時,會出現空白頁。 如果我復制此頁面並將其復制到設備的瀏覽器中,則可以正常看到它。 另外,如果我在虛擬設備上運行它,則在應用程序和瀏覽器上也可以正常看到該頁面。 所以我的問題出在設備上。 我已經有互聯網許可。

編輯-使用其他URL( http://www.globo.com/

代碼: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");
    }

代碼: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" />

因為在網址中

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

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

當您在系統中的虛擬設備上運行它時,僅會從系統訪問同一文件。 但是當你運行的實際device..it同樣不會讓你的系統AP以及該stream_simple.html文件,該文件是在您的系統。 多數民眾贊成y webview顯示空白頁。

stream_simple.html文件放入您的android項目的assests文件夾中,然后將其加載到webview中,將為您提供所需的輸出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM