App8 for group purchases using imitation handles-More modules and app8 for group purchases using handles-Modules
1. Obtain the cache size and clear the cache
All data paths in the application:
/Data/com. xxx. xxx/cache-in-app cache (Note: Corresponding Method getCacheDir ())
/Data/com. xxx. xxx/databases-in-app Database
/Data/com. xxx. xxx/shared_prefs-application configuration file
/Data/com. xxx. xxx/files-files in the application (Note: Corresponding Method getFilesDir ())
Public class DataClearUtil {/*** clear internal cache * @ param context */public static void cleanInternalCache (Context context) {deleteFileByDirectory (context. getCacheDir ();}/*** clear external cache * @ param context */public static void cleanExternalCache (Context context) {if (Environment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED) {deleteFileByDirectory (context. getExternalCacheDir ();}/*** clear In addition to the database cache * @ param context */public static void cleanDatabase (Context context) {deleteFileByDirectory (new File ("/data/" + context. getPackageName () + "/databases");}/*** clear SharedPreference cache * @ param context */public static void cleanSharedPreference (Context context) {deleteFileByDirectory (new File ("/data/" + context. getPackageName () + "/shared_prefs");}/*** clear cache in custom path * @ param filepath */Public static void cleanCustomCache (String filepath) {deleteFileByDirectory (new File (filepath ));} /*** clear the cache in the files Folder * @ param context */public static void cleanFiles (Context context) {deleteFileByDirectory (context. getFilesDir ();}/*** Delete specified database name * @ param context * @ param databaseName */public static void cleanDatabaseByName (Context context, String databaseName) {context. deleteDatabase (DatabaseName);}/*** clear all data in the App * @ param context * @ param filePaths */public static void cleanApplicationData (Context context, String... filePaths) {cleanInternalCache (context); cleanExternalCache (context); cleanDatabase (context); cleanSharedPreference (context); cleanFiles (context); if (filePaths! = Null) {for (String filePath: filePaths) {cleanCustomCache (filePath) ;}}/ *** delete all files in the specified directory, do not process folders * @ param cacheDir */private static void deleteFileByDirectory (File cacheDir) {/* if (cacheDir! = Null & cacheDir. exists () & cacheDir. isDirectory () {for (File file: cacheDir. listFiles () {file. delete () ;}} */if (cacheDir = null |! CacheDir. exists () {return;} if (cacheDir. isDirectory () {File [] files = cacheDir. listFiles (); for (File file: files) {if (file. isDirectory () {deleteFileByDirectory (file);} else {file. delete () ;}} cacheDir. delete ();}/*** get the total Cache size * @ param context * @ return */public static String getTotalCacheSize (Context context) {long folderSize = getFolderSize (context. getCacheDir (); if (Enviro Nment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED) {folderSize + = getFolderSize (context. getExternalCacheDir ();} return getFormatSize (folderSize);}/*** clear all caches */public static void cleanAllCache (Context context) {deleteDir (context. getCacheDir (); if (Environment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED) {deleteDir (context. getExternalCacheDir ());}}/*** Delete all files and folders in the specified directory * @ param dir * @ return */public static boolean deleteDir (File dir) {if (dir = null &&! Dir. exists () {return false;} if (dir. isDirectory () {for (File file: dir. listFiles () {boolean isSuccess = deleteDir (file); if (! IsSuccess) {return false ;}} return dir. delete ();}/*** get the folder size * @ param file * @ return */public static long getFolderSize (File file) {long size = 0; try {File [] fileList = file. listFiles (); for (int I = 0; I <fileList. length; I ++) {if (fileList [I]. isDirectory () {size + = getFolderSize (fileList [I]);} else {size + = fileList [I]. length () ;}} catch (Exception e) {e. printStackTrace ();} return size;}/*** get the formatted file size * @ param size * @ return */public static String getFormatSize (double size) {double kiloByte = size/1024; if (kiloByte <1) {return size + "Byte";} double megaByte = kiloByte/1024; if (megaByte <1) {BigDecimal result1 = new BigDecimal (Double. toString (kiloByte); return result1.setScale (2, BigDecimal. ROUND_HALF_UP ). toPlainString () + "KB";} double gigaByte = megaByte/1024; if (gigaByte <1) {BigDecimal result2 = new BigDecimal (Double. toString (megaByte); return result2.setScale (2, BigDecimal. ROUND_HALF_UP ). toPlainString () + "MB";} double teraByte = gigaByte/1024; if (teraByte <1) {BigDecimal result3 = new BigDecimal (Double. toString (gigaByte); return result3.setScale (2, BigDecimal. ROUND_HALF_UP ). toPlainString () + "GB";} BigDecimal result4 = new BigDecimal (Double. toString (teraByte); return result4.setScale (2, BigDecimal. ROUND_HALF_UP ). toPlainString () + "TB ";}}
2. Application rating
/*** Open the App Store * @ param packageName */private void openAppMarket (String packageName) {try {String str = "market: // detail? Id = "+ packageName; Intent intent = new Intent (Intent. ACTION_VIEW); intent. setData (Uri. parse (str); startActivity (intent);} catch (Exception e) {ToastUtil. show (getActivity (), R. string. open_app_market_failed); e. printStackTrace (); // String url = "https://github.com/myxh"; Intent intent = new Intent (Intent. ACTION_VIEW); intent. setData (Uri. parse (url); startActivity (intent );}}
3. Check for updates
BmobUpdateAgent.forceUpdate(getActivity());