yanchenko yanchenko - 7 months ago 43
Android Question

Getting installed app size

I'm trying to figure out how to get the size of an installed app.

What's already failed:


new File('/data/app/some.apk')
- reports incorrect size

PackageManager.getPackageSizeInfo(String packageName, IPackageStatsObserver observer)
- is
and relies on some obscure
for result so I can't call it via reflection.


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() {

        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.