简体   繁体   English

Android Webview 给出 net::ERR_CACHE_MISS 消息

[英]Android Webview gives net::ERR_CACHE_MISS message

I built a web app and wants to create an android app that has a webview that shows my web app.我构建了一个网络应用程序,并希望创建一个具有显示我的网络应用程序的 web 视图的 android 应用程序。 After following the instructions from Google Developer to create an app, I successfully installed it on my phone with Android 5.1.1.按照 Google Developer 的说明创建一个应用程序后,我成功地将它安装在我的手机上,Android 5.1.1。

However, when I run the app for the first time, the webview shows the message:但是,当我第一次运行该应用程序时,webview 会显示以下消息:

Web page not available网页无法显示

The Web page at [Lorem Ipsum URL] could not be loaded as: [Lorem Ipsum URL] 的网页无法加载为:

net::ERR_CACHE_MISS网络::ERR_CACHE_MISS

I solved the problem by changing my AndroidManifest.xml .我通过更改我的AndroidManifest.xml解决了这个问题。

old : <uses-permission android:name="android.permission.internet"/>旧: <uses-permission android:name="android.permission.internet"/>
new: <uses-permission android:name="android.permission.INTERNET"/>新: <uses-permission android:name="android.permission.INTERNET"/>

Answers assembled!答案汇总! I wanted to just combine all the answers into one comprehensive one.我想将所有答案合并为一个综合答案。

1. Check if <uses-permission android:name="android.permission.INTERNET" /> is present in manifest.xml . 1.检查manifest.xml是否存在<uses-permission android:name="android.permission.INTERNET" /> Make sure that it is nested under <manifest> and not <application> .确保它嵌套在<manifest>而不是<application> Thanks to sajid45 and Liyanis Velazquez感谢sajid45Liyanis Velazquez

2. Ensure that you are using <uses-permission android:name="android.permission.INTERNET"/> instead of the deprecated <uses-permission android:name="android.permission.internet"/> . 2.确保您使用的是<uses-permission android:name="android.permission.INTERNET"/>而不是已弃用的<uses-permission android:name="android.permission.internet"/> Much thanks to alan_shi and creos .非常感谢alan_shicreos

3. If minimum version is below KK, check that you have 3.如果最低版本低于 KK,请检查您是否有

if (18 < Build.VERSION.SDK_INT ){
    //18 = JellyBean MR2, KITKAT=19
    mWeb.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
}

or或者

if (Build.VERSION.SDK_INT >= 19) {
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}

because proper webview is only added in KK (SDK 19).因为正确的 webview 仅在 KK (SDK 19) 中添加。 Thanks to Devavrata , Mike ChanSeong Kim and Liyanis Velazquez感谢Devavrata , Mike ChanSeong KimLiyanis Velazquez

4. Ensure that you don't have webView.getSettings().setBlockNetworkLoads (false); 4.确保你没有webView.getSettings().setBlockNetworkLoads (false); . . Thanks to TechNikh for pointing this out.感谢TechNikh指出这一点。

5. If all else fails, make sure that your Android Studio, Android SDK and the emulator image (if you are using one) is updated. 5.如果所有其他方法都失败了,请确保您的 Android Studio、Android SDK 和模拟器映像(如果您正在使用)已更新。 And if you are still meeting the problem, just open a new question and make a comment below to your URL.如果您仍然遇到问题,只需打开一个新问题并在下面对您的 URL 发表评论。

I tried above solution, but the following code help me to close this issue.我尝试了上述解决方案,但以下代码可帮助我解决此问题。

if (18 < Build.VERSION.SDK_INT ){
    //18 = JellyBean MR2, KITKAT=19
    mWeb.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
}

For anything related to the internet, your app must have the internet permission in ManifestFile.对于与 Internet 相关的任何内容,您的应用程序必须在 ManifestFile 中具有 Internet 权限。 I solved this issue by adding permission in AndroidManifest.xml我通过在AndroidManifest.xml添加权限解决了这个问题

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

Android WebView fix ERR_CACHE_MISS error solution Android WebView 修复ERR_CACHE_MISS错误的解决方法

you just need add one line code <uses-permission android:name="android.permission.INTERNET"/> in your app/src/main/AndroidManifest.xml file as below screenshots shows.你只需要在你的app/src/main/AndroidManifest.xml文件中添加一行代码<uses-permission android:name="android.permission.INTERNET"/>如下图所示。

在此处输入图片说明

  1. before

在此处输入图片说明

  1. after

在此处输入图片说明

To Solve this Error in Webview Android, First Check the Permissions in Manifest.xml, if not define there,then define as like this.要解决Android Webview中的这个错误,首先检查Manifest.xml中的权限,如果没有定义,则像这样定义。 <uses-permission android:name="android.permission.INTERNET"/>

Use

if (Build.VERSION.SDK_INT >= 19) {
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    }

It should solve the error.它应该解决错误。

还要确保您的代码对于 setBlockNetworkLoads 没有 true

webView.getSettings().setBlockNetworkLoads (false);

I have found an answer to my problem. 我找到了问题的答案。 It was because I accidentally nested the permission in the application in AndroidManifest.xml . 这是因为我意外地在AndroidManifest.xml嵌套了应用程序中的权限。

@Bidhan Although I did not use what commented, thank you for your quick response @Bidhan虽然我没有使用评论,感谢您的快速回复

I ran to a similar problem and that was just because of the extra spaces:我遇到了类似的问题,这只是因为多余的空格:

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

which when removed works fine:删除后可以正常工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android WebView 上单。html 文件给出“net::ERR_CACHE_MISS” - Android WebView on a single .html file gives “net::ERR_CACHE_MISS” Android Webview中的loadUrl()因net :: ERR_CACHE_MISS而失败 - loadUrl() in Android Webview fails with net::ERR_CACHE_MISS ner :: ERR_CACHE_MISS Android 4.4 WebView - ner::ERR_CACHE_MISS Android 4.4 WebView 在Android模拟器上,尝试加载webview我得到net :: err_cache_miss - On Android emulator, trying to load a webview i get net::err_cache_miss 调试输出上的Android net :: ERR_CACHE_MISS - Android net::ERR_CACHE_MISS on debug output Android 4.4 在 onReceivedError 中为 WebView 返回 ERR_CACHE_MISS 错误 - Android 4.4 giving ERR_CACHE_MISS error in onReceivedError for WebView back 无法使用WebView加载网址:ERR_CACHE_MISS - Couldn't load url with WebView : ERR_CACHE_MISS 网址URL直接的APP表示“网页不可用”,在仿真器上表示“ net :: ERR_CACHE_MISS” - ANDROID URL DIRECT APP SAYS “web page not available”, ON EMULATOR IT SAYS “net::ERR_CACHE_MISS” 在Cordova中加载外部URL时“net :: ERR_CACHE_MISS” - “net::ERR_CACHE_MISS” when loading an external URL in Cordova 离线缓存 webview 中的网页仅在某些网站中抛出 ERR_CACHE_MISS - Caching the webpage in webview offline throws ERR_CACHE_MISS only in some websites
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM