Android Q(API级别29)不会加载HTTPS网站.给出错误:(net :: ERR_ACCESS_DENIED) [英] Android Q (API level 29) doesn't load HTTPS websites. Gives error: (net::ERR_ACCESS_DENIED)

查看:3748
本文介绍了Android Q(API级别29)不会加载HTTPS网站.给出错误:(net :: ERR_ACCESS_DENIED)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在此处将Stackoverflow上的问题修复为人试图利用WebView加载Facebook网站" https://facebook.com/",但无法完成.我看了一下代码,发现onReceivedSslError()方法没有被覆盖.我覆盖了它,并在运行Android 9(API级别28)及更低版本的Android模拟器上对它进行了测试,即使未添加cleartextTrafficPermitted ,它也可以运行,但是,在Android Q(API级别29)上进行了测试. ,我收到此错误:

I was trying fix an issue here on Stackoverflow as the person was trying to make use of WebView to load Facebook's website "https://facebook.com/" but couldn't get it done. I looked at the code and saw that the onReceivedSslError() method was not overridden. I overrode it and tested it out myself on Android emulators running Android 9 (API level 28) and lower and it worked even without adding the cleartextTrafficPermitted however, on testing on Android Q (API level 29), I was getting this error:

net :: ERR_ACCESS_DENIED

net::ERR_ACCESS_DENIED

这是onCreate方法的副本:

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


        WebView webDimrah = findViewById(R.id.WebView1);
        WebSettings webSettingDimrah = webDimrah.getSettings();
        webSettingDimrah.setJavaScriptEnabled(true);
        webDimrah.setWebViewClient(new WebViewClient(){

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                super.onReceivedSslError(view, handler, error);
                handler.proceed();
            }

            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.getUrl().toString());
                return true;
            }
        });
        webDimrah.loadUrl("https://facebook.com/");

    }

Internet权限已添加到清单文件.任何有关如何解决此问题的建议将不胜感激:)

Internet permission has been added to the manifest file. Any suggestions on how to solve this would be highly appreciated :)

推荐答案

在清单中确保添加android:usesCleartextTraffic="true"

Android 6.0在android清单中的application元素下引入了useCleartextTraffic属性. Android P中的默认值为"false".将此设置为true表示该应用程序打算使用清晰的网络流量.

Android 6.0 introduced the useCleartextTraffic attribute under application element in android manifest. The default value in Android P is "false". Setting this to true indicates that the app intends to use clear network traffic.

这篇关于Android Q(API级别29)不会加载HTTPS网站.给出错误:(net :: ERR_ACCESS_DENIED)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆