Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在不使用网络的情况下使用webview.loadData(…)加载缓存的图像_Android_Caching_Webview - Fatal编程技术网

Android 如何在不使用网络的情况下使用webview.loadData(…)加载缓存的图像

Android 如何在不使用网络的情况下使用webview.loadData(…)加载缓存的图像,android,caching,webview,Android,Caching,Webview,请帮帮我 我使用loadData(…)将html数据加载到webView中 此数据包含 如果网络可用,我希望从web加载此图像;如果网络不可用,则希望从缓存使用此图像 我没有使用javascript。 我更喜欢在webView或android中使用这种机制 //使用缓存映像的第一个写入逻辑 //First write logic of caching image using mWebView.getSettings().setCacheMode(WebSettings.LOAD

请帮帮我

我使用
loadData(…)
将html数据加载到
webView

此数据包含

如果网络可用,我希望从web加载此图像;如果网络不可用,则希望从缓存使用此图像

我没有使用javascript。 我更喜欢在webView或android中使用这种机制

//使用缓存映像的第一个写入逻辑
    //First write logic of caching image using 
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mWebView.getSettings().setAppCachePath(....)
    //Although I do not recommend using above method. Cache image using alternative method. 


    if(check internet connection method)
               + "<img  src=\"http://external.com/some.jpg\">"
    else
                            + "</img>
                            + "<img  src=\"file:///android_asset/some.jpg\">"
                            + "</img>
//android_asset folder if file is shipped with apk or path captured above
mWebView.getSettings().setCacheMode(WebSettings.LOAD\u CACHE\u ELSE\u网络); mWebView.getSettings().setAppCachePath(..) //虽然我不建议使用上述方法。使用替代方法缓存图像。 if(检查互联网连接方法) + "" 其他的 + " + "" + " //android_资产文件夹,如果文件附带apk或上面捕获的路径