0

I have xampp installed and setup "Microsoft LoopBack Adaptor" and was able to access my webpage at "http://localhost/Apryx/audiovideo/" with following snipet of code in my activity onCreate method.

WebView mainWebView = (WebView) findViewById(R.id.act1WebView);
    mainWebView.getSettings().setAppCacheMaxSize( 5 * 1024 * 1024 ); // 5MB
    mainWebView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
    mainWebView.getSettings().setAllowFileAccess( true );
    mainWebView.getSettings().setAppCacheEnabled( true );
    mainWebView.getSettings().setJavaScriptEnabled( true );
    mainWebView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT ); // load online by default

    if ( !isNetworkAvailable() ) { // loading offline
        mainWebView.getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK );
    }

    mainWebView.loadUrl( "http://10.0.2.2/Apryx/audiovideo" );

Problem is, it keeps getting out and opening in browser , i want it to open in webView of app.

Community
  • 1
  • 1
Zulqurnain Jutt
  • 298
  • 3
  • 20

1 Answers1

1

Well i found the bug, i was not mentioning HTML file name to open in URL :

replaced this:

mainWebView.loadUrl( "http://10.0.2.2/Apryx/audiovideo" );

to this:

mainWebView.loadUrl( "http://10.0.2.2/Apryx/audiovideo/index.html" );

and worked like a charm

Zulqurnain Jutt
  • 298
  • 3
  • 20
  • Genius brother. My localhost link kept on opening in the browser until I find this answer! – vss Jan 24 '19 at 11:34