1

I created a WebView app in Android Studio based on a React project When I compile my Java code it shows this error in the emulator:

Webpage not available

The webpage at http://localhost:3000/ could not be loaded because

net::ERR_CLEARTEXT_NOT_PERMITTED

Screenshot of error

This is my Java code:

mySite = (WebView)findViewById(R.id.site);
        mySite.loadUrl("http://127.0.0.1:3000/");
        WebSettings setari = mySite.getSettings();
        setari.setJavaScriptEnabled(true);
        setari.setGeolocationEnabled(true);
        mySite.setWebChromeClient(new WebChromeClient() {
            public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
                callback.invoke(origin, true, false);
            }
        });
        mySite.getSettings().setDomStorageEnabled(true);
        mySite.getSettings().setDatabaseEnabled(true);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            mySite.getSettings().setDatabasePath("/data/data/" + mySite.getContext().getPackageName() + "/databases/");
        }
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
Cosmin Ciolacu
  • 406
  • 9
  • 29
  • Use 10.0.2.2 to access your actual machine. https://stackoverflow.com/questions/5528850/how-do-you-connect-localhost-in-the-android-emulator?lq=1 – Alvaro Arranz Oct 14 '19 at 08:18
  • 1
    https://stackoverflow.com/questions/52707918/webview-showing-err-cleartext-not-permitted-although-site-is-https#answer-52708032 – Lingeshwaran Oct 14 '19 at 08:18
  • 1
    possible duplicate https://stackoverflow.com/questions/58338472/impossible-to-connect-to-a-local-api-on-android-studio/58339186#58339186 – Joachim Haglund Oct 14 '19 at 08:44

0 Answers0