Android Package Size
Unfortunately there is currently no public api to retrieve size information about application packages. However, building on a technique I wrote about in the past, we can use the PackageManager
’s hidden getPackageSize
method to retrieve an instance of PackageStats
that includes cache, code and data size information.
First of all our application will need the GET_PACKAGE_SIZE
permission:
Using ADT we can import the relevant AIDLs (PackageStats
and IPackageStatsObserver
) into our project and have ADT generate stubs. With the stubs generated, we can simply use reflection to call the hidden getPackageSize
method and retrieve the PackageStats
instance in the stub’s onGetStatsCompleted
callback method:
While this works it is obviously a big hack to work around a missing piece of Android API. Reaching past the SDK is never a good idea, especially for public applications.