Android存储空间显示错误

时间:2018-12-27 22:09:28

标签: android local-storage

我对应用程序的可用存储进行了测试,该应用使用本地私有存储。无论我用什么方法调用,它都不会显示什么Android文件浏览器或Windows浏览器。

这是我的代码:

public static long getAvailableMemory()
    {
    Log.i(TAG, "getAvailableMemory: start");
    long bytesAvailable = 0;
    try
        {
        StatFs stat;
        // Root
        stat = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        bytesAvailable = stat.getAvailableBytes();
        Log.d(TAG, "Root.Absolute.AvailableBytes = " + bytesAvailable);
        bytesAvailable = stat.getFreeBytes();
        Log.d(TAG, "Root.Absolute.FreeBytes = " + bytesAvailable);
        // Data
        stat = new StatFs(Environment.getDataDirectory().getAbsolutePath());
        bytesAvailable = stat.getAvailableBytes();
        Log.d(TAG, "Data.Absolute.AvailableBytes = " + bytesAvailable);
        bytesAvailable = stat.getFreeBytes();
        Log.d(TAG, "Data.Absolute.FreeBytes = " + bytesAvailable);
        // External
        stat = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
        bytesAvailable = stat.getAvailableBytes();
        Log.d(TAG, "External.Absolute.AvailableBytes = " + bytesAvailable);
        bytesAvailable = stat.getFreeBytes();
        Log.d(TAG, "External.Absolute.FreeBytes = " + bytesAvailable);
        // Local
        File file = new File(Settings.pathToThumbnails);
        bytesAvailable = file.getUsableSpace();
        Log.d(TAG, "File.UsableSpace = " + bytesAvailable);
        }
    catch (Exception e)
        {
        e.printStackTrace();
        }
    //      Log.d(TAG, "getAvailableMemory: bytesAvailable = " + bytesAvailable);
    return bytesAvailable;
    }

Android文件浏览器:1.65GB

Windows文件浏览器:1,745,756,160(1.62)

运行该应用程序,登录:

12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: Root.Absolute.AvailableBytes = 209154048
12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: Root.Absolute.FreeBytes = 209154048
12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: Data.Absolute.AvailableBytes = 1769209856
12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: Data.Absolute.FreeBytes = 1774452736
12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: External.Absolute.AvailableBytes = 1748234240
12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: External.Absolute.FreeBytes = 1748234240
12-24 08:06:58.966 11835-11835 D/*~MAIN ACTIVITY: File.UsableSpace = 1769205760

我不确定用于测试我的应用的实际数字。我不知道Android报告的1.65 GB来自何处。我只想知道我的应用还剩下多少可用存储空间来将缩略图保存到本地私有存储中。

0 个答案:

没有答案