2016-07-05 55 views
1

我已經使用科爾多瓦3.6.3版本來建立我的android應用程序,我想在科爾多瓦webview中禁用URL緩存,我正在使用默認的cordova項目,使用index.html文件。 我試過,但它崩潰我的應用程序如何禁用科爾多瓦的緩存android應用

public class MyClass extends CordovaActivity 
{ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    mwebview=(WebView) findViewById(R.id.appView); 
    WebSettings ws=mwebview.getSettings(); 
    ws.setAppCacheEnabled(false); 
    ws.setCacheMode(WebSettings.LOAD_NO_CACHE); 
    // Set by <content src="index.html" /> in config.xml 
    loadUrl(launchUrl); 
    } 
} 
+0

您可能會發現這有幫助:http://stackoverflow.com/questions/22221395/turn-off-caching-on-android-for-webapps –

+0

我試過這個,但我無法找到appView.getSettings( )在我的代碼 – Nishant

+0

我已經在我的文章中共享代碼 – Nishant

回答

0

我會建議您使用以下插件:

https://github.com/moderna/cordova-plugin-cache

document.addEventListener('deviceready', onDeviceReady); 
function onDeviceReady() { 
    var success = function(status) { 
     alert('Message: ' + status); 
    } 
    var error = function(status) { 
     alert('Error: ' + status); 
    } 
    window.cache.clear(success, error); 
} 

這將清除您的應用程序每次你啓動緩存它。

您可以在回調中評論警報。

+0

但我想禁用創建緩存 – Nishant

+0

也許這就是你想要的:https://github.com/wongatech/cordova-disable-nsurl-cache –

+0

但是這是用於IOS的。我需要它爲Android – Nishant

0

Cordova(由於運行在webview之上)尊重nocache頭,如果你能夠在你的服務器中設置它,它應該給你相同的結果。另外,您可以通過過期等來控制緩存本身的使用。

0

科爾多瓦 - 禁用 - HTTP緩存

科爾多瓦插件HTTP請求和響應的完全禁用緩存。

在科爾多瓦CLI只需鍵入以下命令:

cordova plugin add cordova-disable-http-cache 

它將取出通過NPM插件「科爾多瓦 - 禁用 - HTTP緩存」和安裝「科爾多瓦 - 禁用 - HTTP緩存」的機器人。

它解決了我的應用程序中禁用緩存的問題。 我的科爾多瓦版本是6.5.0。