【问题标题】:WebView keeps Opening 10.0.2.2 in browserWebView 在浏览器中保持打开 10.0.2.2
【发布时间】:2016-03-28 00:27:39
【问题描述】:

我已安装并设置了“Microsoft LoopBack Adaptor”xampp,并且能够在我的活动 onCreate 方法中使用以下代码片段访问我的网页“http://localhost/Apryx/audiovideo/”。

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" );

问题是,它一直在浏览器中打开,我希望它在应用程序的 webView 中打开。

【问题讨论】:

    标签: java android webview xampp localhost


    【解决方案1】:

    我发现了这个错误,我没有提到要在 URL 中打开的 HTML 文件名:

    替换了这个:

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

    到这里:

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

    并且工作得像个魅力

    【讨论】:

    • 天才兄弟。我的 localhost 链接一直在浏览器中打开,直到我找到这个答案!
    猜你喜欢
    • 2016-12-29
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 2011-07-30
    • 2013-02-05
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    相关资源
    最近更新 更多