Return friendly application size - Android java.lang

Android examples for java.lang:long

Description

Return friendly application size

Demo Code

import android.annotation.SuppressLint;
import android.content.Context;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;

public class Main{

    public static String friendly_appsize(long size) {
        if (size < 1 * 1024 * 1024) {
            return size / 1024 + "KB";
        } else {//from ww  w. j a v  a 2 s  .c o m
            float total = (size * 1.0f) / 1024 / 1024;
            DecimalFormat df = new DecimalFormat("###.00");
            String showText = df.format(total);

            return showText + "MB";
        }
    }

}

Related Tutorials