WebView显示ERR_CLEARTEXT_NOT_PERMITTED,尽管站点是HTTPS

时间:2018-10-08 18:11:35

标签: android android-webview

我开始在Android上的应用程序上工作,所以我没有太多。到目前为止,我所拥有的只是一个WebView。我在Android Studio中创建了该项目,然后将我的项目设置为Android InstantApp。我不确定为什么/如何做,但是我猜是在创建项目时我忽略了它的选项。

我从WebView收到一条错误消息,说net :: ERR_CLEARTEXT_NOT_PERMITTED。当我搜索错误时,我看到当一个应用程序是InstantApp时,WebViews只能加载HTTPS站点,而不能加载HTTP站点。

此应用程序的目的是成为仅用于一个站点的极其简单的Flash播放器。这样可以在需要Flash的游戏中获得更好的性能。该游戏位于darkorbit.com,即HTTPS。

MainActivity.java:

package com.tylerr147.darkorbit;

import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView wv = findViewById(R.id.webView1);
        wv.loadUrl("https://darkorbit.com/");
        wv.setWebViewClient(new CustomWebViewClient());
        WebSettings webSettings = wv.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);

    }
}

和CustomWebViewClient.java

package com.tylerr147.darkorbit;

import android.webkit.WebView;
import android.webkit.WebViewClient;

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

我的问题: 如何将我的应用程序禁用为InstantApp,或者如何使该WebView显示网站?

我觉得重要的是我还要提到其他一些细节: 在显示WebView的应用程序中,它还显示“ http://darkorbit.com/处的网页”无法加载,原因是: 净:: ERR_CLEARTEXT_NOT_PERMITTED

即使URL的字符串是硬编码的,也要注意“ {... {3}}的站点...”,而不是“ http://darkorbit.com/的站点...”,并说“ https://darkorbit.com/”。另外,我正在设置为运行Android 9的Google Pixel 2的模拟器上测试该应用。

任何帮助将不胜感激。谢谢。

3 个答案:

答案 0 :(得分:91)

解决方案:

在您的application标签中添加以下行:

android:usesCleartextTraffic="true"

如下所示:

<application
    ....
    android:usesCleartextTraffic="true"
    ....>

希望有帮助。

答案 1 :(得分:3)

当您调用“ https://darkorbit.com/”时,服务器认为它缺少“ www”,因此它将调用重定向到“ http://www.darkorbit.com/”,然后再重定向到“ https://www.darkorbit.com/”,则您的WebView调用是由于它是“ http”调用,因此在首次重定向时被阻止。 您可以改用“ https://www.darkorbit.com/”来解决问题。

答案 2 :(得分:2)

# query all users in multiple OUs
(Get-ADOrganizationalUnit -Filter *).DistinguishedName |
ForEach{
    # Collect all members of the current OU
    $AccountNames = Get-ADUser -SearchBase $PSItem -Filter *

    # Process each member in the current OU collection
    ForEach($AccountName in $AccountNames)
    {
        "Processing $($AccountName.SamAccoutnName)`n"

        # Initialize properties needed for processing
        $UserOrg = $AccountName.DistinguishedName.split(",")[1]
        $MemberCheckOU = "OU=Admin-User-Accounts,OU=Administration,OU=ORG1,OU=$UserOrg,DC=domain,DC=net"
        $NonCompliantOU = "OU=Groups,OU=ORG1,OU=Information Assurance,OU=$UserOrg,DC=domain,DC=net"

        # Validate user file existence for the current user
        If(-Not (Test-Path -LiteralPath "\\domain.net\SYSVOL\domain.net\IA\$($AccountName.SamAccoutnName).pdf)"))
        {
            # if no file Process the user groupmebership modification
            "Processing $($AccountName.SamAccoutnName)"

            # Notify that the file was not found and processing is required
            Write-Warning -Message "$($($AccountName.SamAccoutnName).pdf) not found. Process group modify actions"       

            # If the current user is in the MemberCheckOU, add to the NonCompliantOU
            If(Get-ADPrincipalGroupMembership -Identity $($AccountName.SamAccoutnName) | Where-Object -Property DistinguishedName -Match $MemberCheckOU )
            { Add-ADGroupMember -Identity $NonCompliantOU -Members $($AccountName.SamAccoutnName) }
            Else
            {
                # Do something else
            }
        }
        Else
        { 
          # Notify that the file was found and no processing required
          Write-Host "$($AccountName.pdf) found. No further actions taken" -ForegroundColor Green }
    }
}

这是我的清单文件 看看这个Ümañgßürmån

此行已经在那里

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.abitech.ckr_abiwhiz" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
        </provider>
        <provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.emailcomposer.EmailComposerProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/emailcomposer_provider_paths" />
        </provider>
        <provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.plugin.notification.util.AssetProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/localnotification_provider_paths" />
        </provider>
        <receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.TriggerReceiver" />
        <receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.ClearReceiver" />
        <activity android:exported="false" android:launchMode="singleInstance" android:name="de.appplant.cordova.plugin.localnotification.ClickReceiver" android:theme="@android:style/Theme.Translucent" />
    </application>
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

抱歉,发帖太晚 重新启动计算机后,此功能正常工作