开发者

What is the diskspace free and used in android?

开发者 https://www.devze.com 2023-02-10 02:28 出处:网络
A code/simple function that will return the available and u开发者_如何学Gosed diskspace in the main android device.

A code/simple function that will return the available and u开发者_如何学Gosed diskspace in the main android device.

Is making a df command and parsing it the best way? What other methods can be used?

Many thanks in advance


i managed to fix make a nice class.

// PHONE STORAGE
public static long phone_storage_free(){
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long free_memory = stat.getAvailableBlocks() * stat.getBlockSize(); //return value is in bytes

    return free_memory;
}

public static long phone_storage_used(){
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long free_memory = (stat.getBlockCount() - stat.getAvailableBlocks()) * stat.getBlockSize(); //return value is in bytes

    return free_memory;
}

public static long phone_storage_total(){
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long free_memory = stat.getBlockCount() * stat.getBlockSize(); //return value is in bytes

    return free_memory;
}   

// SD CARD
public static long sd_card_free(){

    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long free_memory = stat.getAvailableBlocks() * stat.getBlockSize(); //return value is in bytes

    return free_memory;
}
public static long sd_card_used(){

    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long free_memory = (stat.getBlockCount() - stat.getAvailableBlocks()) * stat.getBlockSize(); //return value is in bytes

    return free_memory;
}
public static long sd_card_total(){

    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long free_memory = stat.getBlockCount() * stat.getBlockSize(); //return value is in bytes

    return free_memory;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号