web视图不加载离线缓存数据 [英] Webview not loading offline cached data

查看:137
本文介绍了web视图不加载离线缓存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,它不会使用缓存,网页视图的一个问题。
我开始我的应用程序时,加载HTML5页面,然后背出来的页面,在手机上输入飞行模式,然后再次尝试进入该网页。它应该被缓存,但我得到一个消息,说的网址无法检索。

这是我关于这个code。难道我做错了什么?

 字符串网站链接=htt​​p://abcd.com;
最后ConnectivityManager conMgr =(ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);最终的NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();如果(activeNetwork =空&放大器;!&放大器; activeNetwork.isConnected()){
    进度= ProgressDialog.show(这一点,请等待,装载在线..);
    。mWebview.getSettings()setCacheMode(WebSettings.LOAD_DEFAULT);
    mWebview.getSettings()setAppCacheMaxSize(1024 * 1024 * 8)。
    mWebview.loadUrl(网站链接);
    的setContentView(mWebview);
}
其他
{
    进度= ProgressDialog.show(这一点,请等待,加载下线..);
    。mWebview.getSettings()setCacheMode(WebSettings.LOAD_CACHE_ONLY);    mWebview.loadUrl(网站链接);
    的setContentView(mWebview);
}


解决方案

您code是确定的。

无论本网站不存在,或者没有得到正确的缓存,或者你忘了添加以下权限:

 <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permisson.ACCESS_WIFI_STATE/>
<使用许可权的android:NAME =android.permission.INTERNET对/>

I am having a problem with Webview in that it will not use the cache. I start my app up, load the HTML5 page, then back out of the page, enter airplane mode on the phone, then try to go to the web page again. It should be cached, but I get a message saying that the URL could not be retrieved.

Here is my code pertaining to this. Am I doing something wrong???

String weblink = "http://abcd.com";
final ConnectivityManager conMgr =  (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);

final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();

if (activeNetwork != null && activeNetwork.isConnected()) {
    progressBar = ProgressDialog.show(this, "Please Wait", "loading online..");
    mWebview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    mWebview.getSettings().setAppCacheMaxSize(1024*1024*8);
    mWebview.loadUrl(weblink);
    setContentView(mWebview);
} 
else 
{
    progressBar = ProgressDialog.show(this, "Please Wait", "loading offline..");
    mWebview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);

    mWebview.loadUrl(weblink);
    setContentView(mWebview);
}

解决方案

Your code is ok.

Either the Website does not exist or didn't get cached correctly, or your forgot to add the following permissions :

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

这篇关于web视图不加载离线缓存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆