开发者

What is the diskspace free and used in android?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜