I using Android WebView to load an URL, the web application uses cache and stores the value in browser Application - > local Storage -> www.123xyz.com -> Scoring
Whenever an activity in web application takes place, it will be stored in the local storage, it is working fine.
Now I want to retrieve that local storage values and store it in the SQLite database of android. If the web application does not perform correctly then I want to retrieve the values from SQLite database and set it in the Scoring Key of the local storage
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
Log.e("Database",getFilesDir().getParentFile().getPath()+"/databases/");
mWebView.getSettings().setDatabasePath(getFilesDir().getParentFile().getPath()+"/databases/");
mWebView.getSettings().setAppCacheMaxSize(1024*1024*8);
Log.e("Cache",getApplicationContext().getCacheDir()+"/scoring");
mWebView.getSettings().setAppCachePath( getApplicationContext().getCacheDir()+"/scoring");
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
String url= getResources().getString(R.string.scoringurl);
mWebView.loadUrl(url);
Update:
Now I am able to access the localstorage through the below code and able to retrieve the values. Now I want to get this value for every 30 seconds or whenever there is a change takes place in localstorage.
Is there any way to do it. I guess it has to be done through timer and without making the application slower, can anyone help me.
mWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
view.evaluateJavascript("javascript:window.localStorage.getItem('scoring')", new ValueCallback<String>() {
@Override public void onReceiveValue(String s) {
Log.e("OnRecieve",s);
}
});
super.onPageFinished(view, url);
}
});