Android中的内部电话存储 [英] Internal phone storage in Android

查看:65
本文介绍了Android中的内部电话存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从应用程序检索手机的内部存储空间?我找到了MemoryInfo,但似乎返回有关当前正在使用的任务使用多少内存的信息.

How can you retrieve your phone internal storage from an app? I found MemoryInfo, but it seems that returns information on how much memory use your currently running tasks.

我正试图让我的应用程序检索可用的内部电话存储空间.

I am trying to get my app to retrieve how much internal phone storage is available.

推荐答案

使用android.os.Environment查找内部目录,然后使用android.os.StatFs对其调用Unix statfs系统调用.无耻地被盗 Android设置应用:

Use android.os.Environment to find the internal directory, then use android.os.StatFs to call the Unix statfs system call on it. Shamelessly stolen from the Android settings app:

File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(this, availableBlocks * blockSize);

这篇关于Android中的内部电话存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆