I've recently migrated from android webview to Crosswalk 13. The only issue i've run into is telling the XWalkView to load content from the app cache.
In my android webview implementation i had implmemented as this
//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();
}
}
As getSettings() has now been removed from XWalk 13, I've been trying to set this using XWalkSettings
inside OnCreate in MainActivity
xWalkSettings = new XWalkSettings(mainWebView.getContext(), null , false);
xWalkSettings.setAppCacheEnabled(true);
and then modifying my looped task
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();
}
}
However any attempt to load cached pages fails with "Internet connection has been lost" alert dialogue. Am I instantiating the XWalkSettings instance incorrectly, or is there another way of achieving this?
I found a way from this link. And changed it slightly. Basically need to use reflection to get access to a non public (afaik) method.
If there's a nicer, cleaner way of doing this I'd love to know :)