Search code examples
androidsizeapkfilesize

How to get the size of installed application?


I am trying to calculate the size of the installed application.

I found an answer here

I have tested it on some devices, and there is no problem except Samsung Galaxy Note3(4.3).

I get this error: java.lang.NoSuchMethodException: getPackageSizeInfo()

I'm wondering is there any other way to get the size of an installed app?


Solution

  • try this...

    public static long getApkSize(Context context, String packageName)
            throws NameNotFoundException {
        return new File(context.getPackageManager().getApplicationInfo(
                packageName, 0).publicSourceDir).length();
    }