Android storage showing the incorrect amount












0














I did a test of available storage for my app, which uses local private storage. No matter what method I call it does not show what Android file browser or Windows browser shows.



Here is my code:



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 file browser : 1.65GB



Windows file browser : 1,745,756,160 (1.62)



Running the app, Log :



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


I am unsure of what actual figure to use for testing my app. I don't know where the 1.65 GB that Android reports comes from. I just want to know how much available storage is left for my app to save thumbnail images to local private storage.










share|improve this question






















  • What exactly do you believe is wrong here? Those numbers are very close, especially when you consider the imperfect matchup of powers of 2 and powers of 10
    – Chris Stratton
    Dec 27 '18 at 22:13










  • I do not think 1.65 GB (Android reports) is close to 1.75 GB (External.AvailableBytes). But more importantly, which is the correct amount to do the error testing on. If I error check the Environment call but the actual amount is less, then it will be an error in writing the file.
    – Samuel
    Dec 27 '18 at 22:14












  • External.AvailableBytes is not reporting "1.75 GB" it is reporting 1748234240 bytes. If you take some time to understand what I just said about powers of 2 vs powers of 10, this is not a very big difference at all, and could be entirely explained by conditions changing over tests even a few milliseconds apart. If you are trying to write a file that large, especially to a device with barely that much space free, you are probably doing something very very wrong
    – Chris Stratton
    Dec 27 '18 at 22:21












  • So is it safe to assume that I can use the External.AvailableBytes method with all confidence to error check if I can write a file to local storage?
    – Samuel
    Dec 27 '18 at 22:23










  • No. Unless the file you want to write is well short of the available space, you have to allow for another app writing something at the same time you are. Writing gigabyte+ files to an Android device is not normal behavior at all.
    – Chris Stratton
    Dec 27 '18 at 22:25


















0














I did a test of available storage for my app, which uses local private storage. No matter what method I call it does not show what Android file browser or Windows browser shows.



Here is my code:



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 file browser : 1.65GB



Windows file browser : 1,745,756,160 (1.62)



Running the app, Log :



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


I am unsure of what actual figure to use for testing my app. I don't know where the 1.65 GB that Android reports comes from. I just want to know how much available storage is left for my app to save thumbnail images to local private storage.










share|improve this question






















  • What exactly do you believe is wrong here? Those numbers are very close, especially when you consider the imperfect matchup of powers of 2 and powers of 10
    – Chris Stratton
    Dec 27 '18 at 22:13










  • I do not think 1.65 GB (Android reports) is close to 1.75 GB (External.AvailableBytes). But more importantly, which is the correct amount to do the error testing on. If I error check the Environment call but the actual amount is less, then it will be an error in writing the file.
    – Samuel
    Dec 27 '18 at 22:14












  • External.AvailableBytes is not reporting "1.75 GB" it is reporting 1748234240 bytes. If you take some time to understand what I just said about powers of 2 vs powers of 10, this is not a very big difference at all, and could be entirely explained by conditions changing over tests even a few milliseconds apart. If you are trying to write a file that large, especially to a device with barely that much space free, you are probably doing something very very wrong
    – Chris Stratton
    Dec 27 '18 at 22:21












  • So is it safe to assume that I can use the External.AvailableBytes method with all confidence to error check if I can write a file to local storage?
    – Samuel
    Dec 27 '18 at 22:23










  • No. Unless the file you want to write is well short of the available space, you have to allow for another app writing something at the same time you are. Writing gigabyte+ files to an Android device is not normal behavior at all.
    – Chris Stratton
    Dec 27 '18 at 22:25
















0












0








0







I did a test of available storage for my app, which uses local private storage. No matter what method I call it does not show what Android file browser or Windows browser shows.



Here is my code:



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 file browser : 1.65GB



Windows file browser : 1,745,756,160 (1.62)



Running the app, Log :



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


I am unsure of what actual figure to use for testing my app. I don't know where the 1.65 GB that Android reports comes from. I just want to know how much available storage is left for my app to save thumbnail images to local private storage.










share|improve this question













I did a test of available storage for my app, which uses local private storage. No matter what method I call it does not show what Android file browser or Windows browser shows.



Here is my code:



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 file browser : 1.65GB



Windows file browser : 1,745,756,160 (1.62)



Running the app, Log :



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


I am unsure of what actual figure to use for testing my app. I don't know where the 1.65 GB that Android reports comes from. I just want to know how much available storage is left for my app to save thumbnail images to local private storage.







android local-storage






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 27 '18 at 22:09









Samuel

53310




53310












  • What exactly do you believe is wrong here? Those numbers are very close, especially when you consider the imperfect matchup of powers of 2 and powers of 10
    – Chris Stratton
    Dec 27 '18 at 22:13










  • I do not think 1.65 GB (Android reports) is close to 1.75 GB (External.AvailableBytes). But more importantly, which is the correct amount to do the error testing on. If I error check the Environment call but the actual amount is less, then it will be an error in writing the file.
    – Samuel
    Dec 27 '18 at 22:14












  • External.AvailableBytes is not reporting "1.75 GB" it is reporting 1748234240 bytes. If you take some time to understand what I just said about powers of 2 vs powers of 10, this is not a very big difference at all, and could be entirely explained by conditions changing over tests even a few milliseconds apart. If you are trying to write a file that large, especially to a device with barely that much space free, you are probably doing something very very wrong
    – Chris Stratton
    Dec 27 '18 at 22:21












  • So is it safe to assume that I can use the External.AvailableBytes method with all confidence to error check if I can write a file to local storage?
    – Samuel
    Dec 27 '18 at 22:23










  • No. Unless the file you want to write is well short of the available space, you have to allow for another app writing something at the same time you are. Writing gigabyte+ files to an Android device is not normal behavior at all.
    – Chris Stratton
    Dec 27 '18 at 22:25




















  • What exactly do you believe is wrong here? Those numbers are very close, especially when you consider the imperfect matchup of powers of 2 and powers of 10
    – Chris Stratton
    Dec 27 '18 at 22:13










  • I do not think 1.65 GB (Android reports) is close to 1.75 GB (External.AvailableBytes). But more importantly, which is the correct amount to do the error testing on. If I error check the Environment call but the actual amount is less, then it will be an error in writing the file.
    – Samuel
    Dec 27 '18 at 22:14












  • External.AvailableBytes is not reporting "1.75 GB" it is reporting 1748234240 bytes. If you take some time to understand what I just said about powers of 2 vs powers of 10, this is not a very big difference at all, and could be entirely explained by conditions changing over tests even a few milliseconds apart. If you are trying to write a file that large, especially to a device with barely that much space free, you are probably doing something very very wrong
    – Chris Stratton
    Dec 27 '18 at 22:21












  • So is it safe to assume that I can use the External.AvailableBytes method with all confidence to error check if I can write a file to local storage?
    – Samuel
    Dec 27 '18 at 22:23










  • No. Unless the file you want to write is well short of the available space, you have to allow for another app writing something at the same time you are. Writing gigabyte+ files to an Android device is not normal behavior at all.
    – Chris Stratton
    Dec 27 '18 at 22:25


















What exactly do you believe is wrong here? Those numbers are very close, especially when you consider the imperfect matchup of powers of 2 and powers of 10
– Chris Stratton
Dec 27 '18 at 22:13




What exactly do you believe is wrong here? Those numbers are very close, especially when you consider the imperfect matchup of powers of 2 and powers of 10
– Chris Stratton
Dec 27 '18 at 22:13












I do not think 1.65 GB (Android reports) is close to 1.75 GB (External.AvailableBytes). But more importantly, which is the correct amount to do the error testing on. If I error check the Environment call but the actual amount is less, then it will be an error in writing the file.
– Samuel
Dec 27 '18 at 22:14






I do not think 1.65 GB (Android reports) is close to 1.75 GB (External.AvailableBytes). But more importantly, which is the correct amount to do the error testing on. If I error check the Environment call but the actual amount is less, then it will be an error in writing the file.
– Samuel
Dec 27 '18 at 22:14














External.AvailableBytes is not reporting "1.75 GB" it is reporting 1748234240 bytes. If you take some time to understand what I just said about powers of 2 vs powers of 10, this is not a very big difference at all, and could be entirely explained by conditions changing over tests even a few milliseconds apart. If you are trying to write a file that large, especially to a device with barely that much space free, you are probably doing something very very wrong
– Chris Stratton
Dec 27 '18 at 22:21






External.AvailableBytes is not reporting "1.75 GB" it is reporting 1748234240 bytes. If you take some time to understand what I just said about powers of 2 vs powers of 10, this is not a very big difference at all, and could be entirely explained by conditions changing over tests even a few milliseconds apart. If you are trying to write a file that large, especially to a device with barely that much space free, you are probably doing something very very wrong
– Chris Stratton
Dec 27 '18 at 22:21














So is it safe to assume that I can use the External.AvailableBytes method with all confidence to error check if I can write a file to local storage?
– Samuel
Dec 27 '18 at 22:23




So is it safe to assume that I can use the External.AvailableBytes method with all confidence to error check if I can write a file to local storage?
– Samuel
Dec 27 '18 at 22:23












No. Unless the file you want to write is well short of the available space, you have to allow for another app writing something at the same time you are. Writing gigabyte+ files to an Android device is not normal behavior at all.
– Chris Stratton
Dec 27 '18 at 22:25






No. Unless the file you want to write is well short of the available space, you have to allow for another app writing something at the same time you are. Writing gigabyte+ files to an Android device is not normal behavior at all.
– Chris Stratton
Dec 27 '18 at 22:25














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53951366%2fandroid-storage-showing-the-incorrect-amount%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53951366%2fandroid-storage-showing-the-incorrect-amount%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas