Android5.1sdk22版本获取系统内存大小代码

Android5.1sdk22版本获取系统内存大小代码,第1张

查看Android不同版本API的地址为:

https://developer.android.google.cn/reference/packages

Android5.1sdk22版本获取系统内存大小代码,第2张

选择对应的Android版本,查看对应的Android模块,即可查找到对应版本的API参考文档:

//计算EMMC和DDR
        TextView txEmmcTotal = v.findViewById(R.id.txEmmcTotal);
        TextView txDDRTotal = v.findViewById(R.id.txDDRTotal);
        TextView txEmmcRest = v.findViewById(R.id.txEmmcRest);
        TextView txDDRRest = v.findViewById(R.id.txDDRRest);

        
        ActivityManager activityManager = (ActivityManager) requireActivity().getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
        activityManager.getMemoryInfo(memoryInfo);
        
        float totalMemory = (float)memoryInfo.totalMem/(1024 * 1024 * 1024);
        Log.e(TAG, "setVersionInfo: totalMemory= "+ String.format("%.2f",totalMemory) + 'G');
        txEmmcTotal.setText(String.format("%.2f",totalMemory) + "GB");
        
        float availMemory = (float)memoryInfo.availMem/(1024*1024*1024);
        Log.e(TAG, "setVersionInfo: availMemory= "+ String.format("%.2f",availMemory) + "GB");
        txEmmcRest.setText(String.format("%.2f",availMemory) + "GB");


         //系统文件大小
        StatFs stat = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long systemSize = stat.getTotalBytes();
        Log.e(TAG, "setVersionInfo: systemSize= "+ String.format("%.2f",systemSize/(1024f * 1024 * 1024)) + "GB");
        txDDRTotal.setText(String.format("%.2f",systemSize/(1024f * 1024 * 1024)) + "GB");

        long availableSize = stat.getAvailableBytes();
        Log.e(TAG, "setVersionInfo: availableSize="+ String.format("%.2f",availableSize/(1024f * 1024 * 1024)) + "GB");
        txDDRRest.setText(String.format("%.2f",availableSize/(1024f * 1024 * 1024)) + "GB");

        //内部sd存储空间大小
//        StatFs stat1 = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
//        Log.e(TAG, "setVersionInfo: getExternalStorageDirectory="+Environment.getExternalStorageDirectory().getAbsolutePath());
//        long internal_sd_totalBlocks = stat1.getBlockCountLong();// 获取block数量
//        long internal_sd_blockSize = stat1.getBlockSizeLong();
//        long internal_sd_totalSize = internal_sd_blockSize *  internal_sd_totalBlocks;
//        Log.e(TAG, "setVersionInfo: internal_sd_totalSize="+ String.format("%.2f",internal_sd_totalSize/(1024f * 1024 * 1024)) + "GB");
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » Android5.1sdk22版本获取系统内存大小代码

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情