Advertisement
Sketchware

Código para mostra TextView Espaço de armazenamento usado celualr

Jan 11th, 2023
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.53 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.  
  8. TextView textView = findViewById(R.id.text_view); // suponha que você tenha um TextView com esse ID no seu layout
  9. textView.setText(message);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement