判断内存卡的可用空间

来源:互联网 发布:软件测试单元测试 编辑:程序博客网 时间:2024/05/22 05:14

                                   /**
                             * 判断内存卡的可用空间
                             *
                             * @param sizeMb
                             * @return
                             */
                        public boolean isAvaiableSpace(int sizeMb) {
                               String sdcard = Environment.getExternalStorageDirectory().getPath();
                               File file = new File(sdcard);
                              StatFs statFs = new StatFs(file.getPath());
                               int availableSpare = (int) (statFs.getBlockSize() *

                                           ((long) statFs.getAvailableBlocks() - 4)) / (1024 * 1024);//内存卡的可用空间(MB)
                                     if (sizeMb > availableSpare) {
                                                   return false;
                                          } else
                                    return true;

                                   }