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
getPackageSize method to retrieve an instance of
PackageStats that includes cache, code and data size information.
First of all our application will need the
Using ADT we can import the relevant AIDLs (
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.