zoukankan      html  css  js  c++  java
  • 获得手机内存空间状态

    示例

    
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            TextView tvMemoryInfo = (TextView) findViewById(R.id.tv_memory_info);
    
            //获取sd卡内存状态
            File sdCardFileDir = Environment.getExternalStorageDirectory();
            String sdcardMemory = getMemoryInfo(sdCardFileDir);
    
            //获取手机内部存储空间的状态
            File dataFileDir = Environment.getDataDirectory();
            String dataMemory = getMemoryInfo(dataFileDir);
            tvMemoryInfo.setText("sd卡" + sdcardMemory + "
    手机内部"+dataMemory);
    
        }
    
        /**
         * 根据路径获取内存状态
         * @param path
         * @return
         */
        private String getMemoryInfo(File path) {
            // 得到路径
            // File path =Environment.getExternalStorageDirectory();
    
            // 获得一个 磁盘状态 对象
            StatFs stat = new StatFs(path.getPath());
    
            long blockSize = stat.getBlockSize(); // 获得一个 扇区大小
    
            long totalBlocks = stat.getBlockCount(); // 获取扇区的总数
    
            long availableBlocks = stat.getAvailableBlocks(); // 获取可用的扇区数量
    
            // 总空间
            String totalMemory = Formatter.formatFileSize(this, totalBlocks * blockSize);
    
            // 可用空间
            String availableMemory = Formatter.formatFileSize(this, blockSize * availableBlocks);
    
            return "总空间" + totalMemory + "
    可用空间"+availableMemory;
        }
    }
  • 相关阅读:
    arcgis10.2 sde配置
    创建只读账号oracle
    oracle 的tnsnames.ora,listener.ora
    gp工具的许可
    复制整个数据库
    显示二维表格的位置计算
    windows文件名格式的中文+数字混合字符串排序
    supergridcontrol记录,分页
    outlook-由于本机的限制,该操作已被取消。请与系统管理员联系。
    自定义单元格式
  • 原文地址:https://www.cnblogs.com/rysinal/p/5834488.html
Copyright © 2011-2022 走看看