get Volume Size - Android android.media

Android examples for android.media:Volume

Description

get Volume Size

Demo Code

import android.content.Context;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String getVolume(long volume) {

        float num = 1.0F;

        String str = null;/* w  w  w .java2 s .  com*/

        if (volume < 1024) {
            str = volume + "B";
        } else if (volume < 1048576) {
            num = num * volume / 1024;
            str = format("%.1f", num) + "K";
        } else if (volume < 1073741824) {
            num = num * volume / 1048576;
            str = format("%.1f", num) + "M";
        } else if (volume < 1099511627776L) {
            num = num * volume / 1073741824;
            str = format("%.1f", num) + "G";
        }

        return str;
    }

}

Related Tutorials