Android Q (API level 29) doesn't load HTTPS websites. Gives error: (net::ERR_ACCESS_DENIED) [duplicate]

可紊 提交于 2019-12-11 07:38:42

问题


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

Here is a copy of the onCreate method:

@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 permission has been added to the manifest file. Any suggestions on how to solve this would be highly appreciated :)


回答1:


Inside your manifest make sure to add android:usesCleartextTraffic="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.




回答2:


You have to use android:usesCleartextTraffic in you manifest.

This flag is ignored on Android 7.0 (API level 24) and above if an Android Network Security Config is present.

Please check the below explanation from Developer site for more details.

https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic



来源:https://stackoverflow.com/questions/58901080/android-q-api-level-29-doesnt-load-https-websites-gives-error-neterr-acc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!