I have listed all the installed applications. When I click any application from the list I want to show the total memory used by that app programmatically(similar to settings->apps). What I tried:
 long apsize = new File(this.getPackageManager().getApplicationInfo(
                packageName, 0).publicSourceDir).length();
        int unit = si ? 1000 : 1024;
        if (apsize < unit) return apsize + " B";
        int exp = (int) (Math.log(apsize) / Math.log(unit));
        String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
        //replacing kib and mib from the value
        return String.format("%.1f %sB", apsize / Math.pow(unit, exp), pre).replace("MiB","").replace("KiB","");
But it returns only the apk size where as I want to get the total memory used by the selected application. Is there a way to get the total memory used by application programmatically?
 
    