Advertisement
Sketchware

Mostra em porcentagem espaço usado do celular

Jan 11th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
  2. long totalSpace = stat.getBlockCountLong() * stat.getBlockSizeLong();
  3. long availableSpace = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
  4. long usedSpace = totalSpace - availableSpace;
  5. long usedSpaceInPercentage = (usedSpace * 100) / totalSpace;
  6. String message = "Espaço Usado: " + usedSpaceInPercentage + "%";
  7. Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
  8.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement