Getting installed app size

Unfortunately there is currently no official way to do that. However, you can call the PackageManager‘s hidden getPackageSize method if you import the PackageStats and IPackageStatsObserver AIDLs into our project and generate the stubs. You can then use reflection to invoke getPackageSize:

PackageManager pm = getPackageManager();

Method getPackageSizeInfo = pm.getClass().getMethod(
    "getPackageSizeInfo", String.class, IPackageStatsObserver.class);

getPackageSizeInfo.invoke(pm, "com.android.mms",
    new IPackageStatsObserver.Stub() {

        @Override
        public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
            throws RemoteException {

            Log.i(TAG, "codeSize: " + pStats.codeSize);
        }
    });

That’s obviously a big hack and should not be used for public applications.

Leave a Comment