我最近从android webview迁移到Crosswalk 13.我遇到的唯一问题是告诉XWalkView从应用缓存中加载内容。
在我的android webview实现中,我已经被认为是这个
//check connection on a loop
public void CheckConnectivityTask(){
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
//runs every 0.5s
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(Void result) {
CheckConnectivity(true);
}
}.execute();
}
public void CheckConnectivity(boolean recursiveTask){
cm = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
if(cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()){
Log.v("ConnectivityGG", "IS CONNECTED");
mainWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
}
else{
mainWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
if(recursiveTask){
CheckConnectivityTask();
}
}
由于getSettings()现已从XWalk 13中删除,我一直在尝试使用XWalkSettings设置它
在MainActivity中的OnCreate
xWalkSettings = new XWalkSettings(mainWebView.getContext(), null , false);
xWalkSettings.setAppCacheEnabled(true);
然后修改我的循环任务
public void CheckConnectivity(boolean recursiveTask){
cm = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
if(cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()){
xWalkSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
}
else{
xWalkSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
if(recursiveTask){
CheckConnectivityTask();
}
}
但是,任何加载缓存页面的尝试都会因“Internet连接已丢失”警报对话而失败。我是否错误地实例化了XWalkSettings实例,还是有另一种实现方法?
答案 0 :(得分:0)
答案 1 :(得分:0)
Crosswalk之前没有公开过setCacheMode API,但最近曝光了,请参阅此JIRA,https://crosswalk-project.org/jira/browse/XWALK-6832
它应该在Crosswalk 21中可用,你可以像下面这样使用它:
mXWalkView.getSettings().setCacheMode(XWalkSettings.LOAD_NO_CACHE);
所以,享受它.. :))