/** File name: datacleanmanager. java * Description: The main functions are to clear the internal/external cache, clear the database, clear sharedpreference, clear files, and clear the custom directory */package COM. test. dataclean; import Java. io. file; import android. content. context; import android. OS. environment;/***** the application data clearing manager */public class datacleanmanager {/***** clears the internal cache of the application (/data/COM. xxx. xxx/cache) ** @ Param context */public static void cleaninternalcache (context) {deletefilesbydirecto Ry (context. getcachedir ();}/*** clear all databases of the application (/data/COM. xxx. xxx/databases) ** @ Param context */public static void cleandatabases (context) {deletefilesbydirectory (new file ("/data/" + context. getpackagename () + "/databases");}/*** clear the sharedpreference (/data/COM. xxx. xxx/shared_prefs) ** @ Param context */public static void cleansharedpreference (context) {delet Efilesbydirectory (new file ("/data/" + context. getpackagename () + "/shared_prefs "));} /*** clear the application database by name ** @ Param context * @ Param dbname */public static void cleandatabasebyname (context, string dbname) {context. deletedatabase (dbname);}/*** clear/data/COM. xxx. content in xxx/Files ** @ Param context */public static void cleanfiles (context) {deletefilesbydirectory (context. get Filesdir ();}/*** clear content in the external cache (/mnt/sdcard/Android/data/COM. xxx. xxx/cache) ** @ Param context */public static void cleanexternalcache (context) {If (environment. getexternalstoragestate (). equals (environment. media_mounted) {deletefilesbydirectory (context. getexternalcachedir () ;}}/*** clear the files in the custom path. Be careful when using the command. Do not delete the files by mistake. Only files in the directory can be deleted ** @ Param filepath */public static void cleancustomcache (string filepath) {deletefilesbydirectory (new file (filepath ));} /*** clear all data of this application ** @ Param context * @ Param filepath */public static void cleanapplicationdata (context, string... filepath) {cleaninternalcache (context); cleanexternalcache (context); cleandatabases (context); cleansharedpreference (context); cleanfiles (C Ontext); For (string filepath: filepath) {cleancustomcache (filepath) ;}}/*** the deletion method only deletes files in a folder, if the imported directory is a file, no processing will be performed ** @ Param directory */Private Static void deletefilesbydirectory (file directory) {If (directory! = NULL & directory. exists () & directory. isdirectory () {for (File item: directory. listfiles () {item. Delete ();}}}}