安卓手机内部存储 [英] android internal phone storage

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

问题描述

你怎么能找回你的手机内部存储从一个应用程序?我发现memoryinfo,但似乎返回多少内存你当前正在运行的任务的信息。我试图让我的应用程序,以获取多少手机内部存储可用。

how can you retrieve yours phone internal storage from an app? I found memoryinfo, but it seems that returns information on how much memory 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 就可以了系统调用。无耻<一href="https://github.com/android/platform_packages_apps_settings/blob/gingerbread/src/com/android/settings/deviceinfo/Memory.java#L335">stolen从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);

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

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