• Android 获取手机本机内存、SD卡内存使用情况


    Android 获取手机本机内存、SD卡内存使用情况

      /**
         * 获得SD卡总大小
         * 
         * @return
         */
        public Long getSDTotalSize() {
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long totalBlocks = stat.getBlockCount();
            return blockSize * totalBlocks;
        }
    
        /**
         * 获得sd卡剩余容量,即可用大小
         * 
         * @return
         */
        public long getSDAvailableSize() {
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long availableBlocks = stat.getAvailableBlocks();
            return blockSize * availableBlocks;
        }
    
        /**
         * 获得机身内存总大小
         * 
         * @return
         */
        public long getRomTotalSize() {
            String str1 = "/proc/meminfo";// 系统内存信息文件
            String str2;
            String[] arrayOfString;
            long initial_memory = 0;
            try {
                FileReader localFileReader = new FileReader(str1);
                BufferedReader localBufferedReader = new BufferedReader(
                        localFileReader, 8192);
                str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小
    
                arrayOfString = str2.split("\s+");
                for (String num : arrayOfString) {
                    Log.i(str2, num + "	");
                }
    
                initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte
                localBufferedReader.close();
    
            } catch (IOException e) {
            }
            return initial_memory;
        }
    
        /**
         * 获得机身可用内存
         * 
         * @return
         */
        public long getRomAvailableSize() {
            ActivityManager am = (ActivityManager) Context.getSystemService(Context.ACTIVITY_SERVICE);
            MemoryInfo mi = new MemoryInfo();
            am.getMemoryInfo(mi);
            return mi.availMem;
        }
  • 相关阅读:
    A New Approach to Line Simplification Based on Image Processing: A Case Study of Water Area Boundaries
    3D模型
    数码相机控制点的自动定位检校
    道路网匹配
    多线程操作数据拷贝要加线程锁
    编程琐事
    C++ 指定路径文件夹存在与否查询及文件夹创建
    C++ 网络编程之正确使用UDP广播及多播
    C++ 获得系统时间
    C++ 数据写入文件与读回
  • 原文地址:https://www.cnblogs.com/fly-allblue/p/4276964.html
Copyright © 2020-2023  润新知