SoFunction
Updated on 2025-03-11

Methods for obtaining system storage and memory information on Android (I)

As we all know, most of the information on Android phones can be obtained through code. For example, iQiyi's offline storage function has a maximum storage size/remaining storage size function.

Get the stored information on the SD card:

  /**
    * Total SD card size obtained
    *
    * @return
    */
  private String getSDTotalSize() {
    File path = ();
    StatFs stat = new StatFs(());
    long blockSize = ();
    long totalBlocks = ();
    return (this, blockSize * totalBlocks);
  }

  /**
    * Get the remaining capacity of the SD card, and you can use the size
    *
    * @return
    */
  private String getSDAvailableSize() {
    File path = ();
    StatFs stat = new StatFs(());
    long blockSize = ();
    long availableBlocks = ();
    return (this, blockSize * availableBlocks);
  }

The memory of the mobile phone system can also be obtained through the () method: as follows:

Get the system's memory size and available memory size:

  /**
    * Get the system memory size
    * @return
    */
  private String getSysteTotalMemorySize(){
    //object to obtain the ActivityManager service    ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    //Get MemoryInfo object     memoryInfo = new () ;
    //Get available memory in the system and save it on the MemoryInfo object    (memoryInfo) ;
    long memSize =  ;
    //Character type conversion    String availMemStr = formateFileSize(memSize);
    return availMemStr ;
  }

  /**
    * Get the available memory size of the system
    * @return
    */
  private String getSystemAvaialbeMemorySize(){
    //object to obtain the ActivityManager service    ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    //Get MemoryInfo object     memoryInfo = new () ;
    //Get available memory in the system and save it on the MemoryInfo object    (memoryInfo) ;
    long memSize =  ;

    //Character type conversion    String availMemStr = formateFileSize(memSize);

    return availMemStr ;
  }

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.