应用程序中的Android webview未加载

时间:2016-10-19 01:23:26

标签: android android-studio android-webview

这样做的目的是让一个网页在中触发应用程序本身。该应用程序运行没有故障,但从未见过该网页。 .xml包含网页及其下方的列表。

.xml文件读为

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_centerVertical="true"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

     <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="500dp"
        android:id="@android:id/list"/>
</LinearLayout>

.java中的活动读为

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView myWebView = new WebView(this);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("https://google.com");

    // Other AWS gibberish
}

我可以将网页作为单独的应用程序启动,但这不是我想要的。

    WebView webview = new WebView(this);
    setContentView(webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://google.ca");

编辑:我已经在清单中添加了互联网权限

<uses-permission android:name="android.permission.INTERNET" />

我使用herehereheredocumentation的一些参考资料未成功

编辑2:浏览设备调试文件并记录以下内容

10-18 22:07:59.296 7717-7717/com.amazon.mysampleapp I/WebViewFactory: Loading com.google.android.webview version 53.0.2785.124 (code 278512400)
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: SBServiceAPI: getService class android.os.ServiceManager
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isShipBuild true
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Thread-46729-141117018: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
10-18 22:07:59.336 7717-7826/com.amazon.mysampleapp I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
10-18 22:07:59.346 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
10-18 22:07:59.366 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 655-661)
10-18 22:07:59.366 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
10-18 22:07:59.376 7717-7717/com.amazon.mysampleapp W/ResourceType: Failure getting entry for 0x01080ad1 (t=7 e=2769) (error -75)
10-18 22:07:59.386 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
10-18 22:07:59.396 7717-7717/com.amazon.mysampleapp I/chromium: [INFO:library_loader_hooks.cc(151)] Chromium logging enabled: level = 0, default verbosity = 0
10-18 22:07:59.436 7717-7717/com.amazon.mysampleapp I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
10-18 22:07:59.606 7717-7826/com.amazon.mysampleapp I/DefaultDeliveryClient: Successful submission of 4 events
10-18 22:07:59.646 7717-7843/com.amazon.mysampleapp W/cr_media: Requires BLUETOOTH permission
10-18 22:07:59.686 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
10-18 22:07:59.696 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
10-18 22:07:59.736 7717-7717/com.amazon.mysampleapp D/ConnectivityManager: CallingUid : 10097, CallingPid : 7717
10-18 22:07:59.736 7717-7854/com.amazon.mysampleapp D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524290
10-18 22:07:59.766 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
10-18 22:07:59.766 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>

1 个答案:

答案 0 :(得分:5)

而不是在onCreate实例化新的Webview,我认为您可能需要使用布局中指定的那个:

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.NAME_OF_THE_XML_FILE); // change here to match the name of your xml file


    // WebView myWebView = new WebView(this); instead of this, try this one below:
    WebView myWebView = (WebView) findViewById(R.id.webview);

    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("https://google.com");

    // Other AWS gibberish
}