Connection to localhost does not work webview Android

Asked

Viewed 330 times

1

If I try to access the server’s localhost directly through Chrome I can log in but through an application the page is empty, follow the code:

public class WebActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.webcontent);

        webView = (WebView) findViewById(R.id.webView);

        webView.getSettings().setJavaScriptEnabled(true);

        webView.loadUrl("192.168.1.66/sir1415/teste/teste.html");


    }
  • Does a logcat error appear in the IDE? Did you ever try to put the protocol in the url? e. g: http://192.192.168.1.66/sir1415/teste/teste.html. I believe the browser does this transparently.

  • No error appears and this setting also does not work

  • Try to use http://10.0.2.2/. This is a special IP address for routes the emulator uses for localhost on your machine.

1 answer

1

I was able to figure out the solution, when using webview for localhost you have to use the port, even if in the browser you DO NOT need the webview always need, that is to say the address is like this: http://192.192.168. 1.66:80/sir1415/test/test.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.