Joseph
Joseph

Reputation: 6031

Android Webview access denied

On Android 9 (Api 29) am trying to load a url and i get the error "The webpage at url could not be loaded because: net::ERR_ACCESS_DENIED".

I have internet the internet permission in the AndroidManifest.xml files

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

From logcat, i can see the the following error as well :

E/chromium: [ERROR:socket_posix.cc(94)] CreatePlatformSocket() failed: Operation not permitted (1)

My code is as follows :

WebView webView = findViewById(R.id.webView);
webView.loadUrl("https://andela.com/alc/");

I later added the following code to get more detail :

webView.setWebViewClient(new WebViewClient(){
    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
        Log.d("TAG", error.getDescription().toString());
        // handler.proceed(); This line wont make a different on API 29, Webview still bank
    }
});

The Webview loads the url properly when using an emulator running API 25. Also tested on API 28 and it works fine. Only doesn't work on API 29.

Upvotes: 17

Views: 17858

Answers (7)

Tijil Parmar
Tijil Parmar

Reputation: 41

Targetting Android S+ will require you to provide file access permission if the html file is accessed from the device storage. Just add the line below:

webview.getSettings().setAllowFileAccess(true);

This resolved the mentioned error for me.

Upvotes: 4

yun abs
yun abs

Reputation: 111

Uninstall application first and reinstall after inserting permission

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

Do not just restart.

Upvotes: 1

ja12
ja12

Reputation: 360

Uninstall the application from the emulator or phone completely and compile or install again. It should already work.

Upvotes: 1

Abhishek Kumar
Abhishek Kumar

Reputation: 131

just uninstall the app and once again install it.That work 100%

Upvotes: 11

Ievgen
Ievgen

Reputation: 476

In my case the web page becomes loading correctly (without ERR_ACCESS_DENIED) after changing applicationId in build.gradle (and run the app, of-course). After that you may return the old applicationId.

Upvotes: 7

TheTechGuy
TheTechGuy

Reputation: 17354

This is broke in the latest "Q Android 10", change target frame work to "Pie- Android 9" which will work. Change by going to

File > Project Structure

Then on left > Modules > Compiler SK Version (change to Api 28)

Note: Install Android PIE if it not already or the option does not appear by going to Preferences then > System Preference > Android SDK on left

Upvotes: 4

Ghazi
Ghazi

Reputation: 186

Might be SSL cert throwing error, try this:

// Ignoring SSL certificate errors

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

You can try building your app with Android Smart WebView framework, it can provide you more insight on what might be going on with your webpage.

Upvotes: -1

Related Questions