Android获取当前可用内存

写入本地文件

private void getMemo(){
        //获得ActivityManager服务的对象
        ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        //获得MemoryInfo对象
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo() ;
        //获得系统可用内存,保存在MemoryInfo对象上
        mActivityManager.getMemoryInfo(memoryInfo) ;
        long memSize = memoryInfo.availMem ;
        selfHttpRequest.writeToLoacl(memSize+"");
        Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
    }

Toast形式

private void toastMemo(){
        //获得ActivityManager服务的对象
        ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        //获得MemoryInfo对象
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo() ;
        //获得系统可用内存,保存在MemoryInfo对象上
        mActivityManager.getMemoryInfo(memoryInfo) ;
        long memSize = memoryInfo.availMem ;
        double mem = memSize / (1000*1000);
        Toast.makeText(this, mem+"MB ", Toast.LENGTH_SHORT).show();
    }
posted @ 2018-06-17 20:34  秦川德利齐  阅读(2713)  评论(2编辑  收藏  举报