55import android .content .res .AssetFileDescriptor ;
66import android .net .Uri ;
77import android .os .Build ;
8+ import android .os .StatFs ;
9+ import android .text .TextUtils ;
810
911import java .io .BufferedInputStream ;
1012import java .io .File ;
@@ -76,10 +78,10 @@ public static boolean isFileExists(final String filePath) {
7678 if (file .exists ()) {
7779 return true ;
7880 }
79- return isFileExists29 (filePath );
81+ return isFileExistsApi29 (filePath );
8082 }
8183
82- private static boolean isFileExists29 (String filePath ) {
84+ private static boolean isFileExistsApi29 (String filePath ) {
8385 if (Build .VERSION .SDK_INT >= 29 ) {
8486 try {
8587 Uri uri = Uri .parse (filePath );
@@ -1379,6 +1381,15 @@ public static String getFileExtension(final String filePath) {
13791381 return filePath .substring (lastPoi + 1 );
13801382 }
13811383
1384+ /**
1385+ * Notify system to scan the file.
1386+ *
1387+ * @param filePath The path of file.
1388+ */
1389+ public static void notifySystemToScan (final String filePath ) {
1390+ notifySystemToScan (getFileByPath (filePath ));
1391+ }
1392+
13821393 /**
13831394 * Notify system to scan the file.
13841395 *
@@ -1393,12 +1404,45 @@ public static void notifySystemToScan(final File file) {
13931404 }
13941405
13951406 /**
1396- * Notify system to scan the file.
1407+ * Return the total size of file system .
13971408 *
1398- * @param filePath The path of file.
1409+ * @param anyPathInFs Any path in file system.
1410+ * @return the total size of file system
13991411 */
1400- public static void notifySystemToScan (final String filePath ) {
1401- notifySystemToScan (getFileByPath (filePath ));
1412+ public static long getFsTotalSize (String anyPathInFs ) {
1413+ if (TextUtils .isEmpty (anyPathInFs )) return 0 ;
1414+ StatFs statFs = new StatFs (anyPathInFs );
1415+ long blockSize ;
1416+ long totalSize ;
1417+ if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
1418+ blockSize = statFs .getBlockSizeLong ();
1419+ totalSize = statFs .getBlockCountLong ();
1420+ } else {
1421+ blockSize = statFs .getBlockSize ();
1422+ totalSize = statFs .getBlockCount ();
1423+ }
1424+ return blockSize * totalSize ;
1425+ }
1426+
1427+ /**
1428+ * Return the available size of file system.
1429+ *
1430+ * @param anyPathInFs Any path in file system.
1431+ * @return the available size of file system
1432+ */
1433+ public static long getFsAvailableSize (final String anyPathInFs ) {
1434+ if (TextUtils .isEmpty (anyPathInFs )) return 0 ;
1435+ StatFs statFs = new StatFs (anyPathInFs );
1436+ long blockSize ;
1437+ long availableSize ;
1438+ if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
1439+ blockSize = statFs .getBlockSizeLong ();
1440+ availableSize = statFs .getAvailableBlocksLong ();
1441+ } else {
1442+ blockSize = statFs .getBlockSize ();
1443+ availableSize = statFs .getAvailableBlocks ();
1444+ }
1445+ return blockSize * availableSize ;
14021446 }
14031447
14041448 ///////////////////////////////////////////////////////////////////////////
0 commit comments