The example in this article describes the Android implementation WebView Delete cache method. Share to everyone for your reference. Specifically as follows:
To delete a cache stored on your phone:
Clear the cache before time numdays
private int Clearcachefolder (File dir, long numdays) {
int deletedfiles = 0 ;
if (dir!= null && dir.isdirectory ()) {
try {for
(File child:dir.listFiles ()) {
if ( Child.isdirectory ()) {
Deletedfiles + = Clearcachefolder (child, numdays);
}
if (child.lastmodified () < numdays) {
if (Child.delete ()) {
deletedfiles++
}
}}} catch (Exception e) {
e.printstacktrace ();
}
}
return deletedfiles;
}
Turn off Use caching:
Priority use caching:
webview.getsettings (). Setcachemode (websettings.load_cache_else_network);
Do not use caching:
webview.getsettings (). Setcachemode (Websettings.load_no_cache);
When you exit the application, add the following code:
File File = Cachemanager.getcachefilebasedir ();
if (file!= null && file.exists () && file.isdirectory ()) {for
(file Item:file.listFiles ()) {
it Em.delete ();
}
File.delete ();
}
Context.deletedatabase ("webview.db");
Context.deletedatabase ("webviewcache.db");
I hope this article will help you with your Android program.