小编Rac*_*hid的帖子

Android WebView 加载失败 (net::ERR_CLEARTEXT_NOT_PERMITTED)

有人能帮助我吗?我在我的 Android 应用程序中使用 WebView

compileSdkVersion 29
buildToolsVersion "29.0.0"
minSdkVersion 16
targetSdkVersion 29
Run Code Online (Sandbox Code Playgroud)

我在 AmdroidManifest 中有配置 https 并创建了一个配置文件但没有更改我收到明文错误:

(净::ERR_CLEARTEXT_NOT_PERMITTED)

@xml/network_security_config

  <?xml version="1.0" encoding="utf-8"?>
  <network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">www.mydomaine.com</domain>
  </domain-config>
  </network-security-config>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml

    <manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
   <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    android:networkSecurityConfig="@xml/network_security_config"
    android:usesCleartextTraffic="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)

WabView 类

    public void LoadWeb() {
    webView = (WebView) findViewById(R.id.webview_test);
    webView.getSettings().setAppCacheEnabled(false);
    webView.clearCache(true);
    webView.reload();
    webView.getSettings().setJavaScriptEnabled(false);
    webView.getSettings().setLoadsImagesAutomatically(true);
        webView.loadUrl("https://www,mydomaine.com");
    swipe.setRefreshing(true);
    webView.setWebViewClient(new WebViewClient() {


        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, …
Run Code Online (Sandbox Code Playgroud)

java android android-webview android-network-security-config

2
推荐指数
1
解决办法
2772
查看次数