2

I want to get the application size (in bytes). The way I tried was as follows:

PackageStats ps = new PackageStats(packageInfo.packageName); int size = ps.codeSize;

This returns 0 every time. (Bascially every value returned is 0 - cacheSize, dataSize etc)

I do not want to use reflection as mentioned here (as its a non documented way)

So is there any way to fetch this information ?

Community
  • 1
  • 1
Amit B
  • 131
  • 1
  • 6
  • see this can help you http://stackoverflow.com/questions/1806286/getting-installed-app-size – Developer Mar 12 '14 at 06:16
  • possible duplicate of http://stackoverflow.com/questions/1806286/getting-installed-app-size?lq=1 – kalyan pvs Mar 12 '14 at 06:16
  • Thanks Guys, However I have already mentioned that I do not want to use non-documented API. I have already mentioned the same link in my second last line – Amit B Mar 12 '14 at 06:24

2 Answers2

0

One definition of application size is the size of the apk file in bytes.

You can get that by doing new File() on the ApplicationInfo.sourceDir value for the application, and then doing a File.length() on that file.

zmarties
  • 4,809
  • 22
  • 39
0

Contrary to the sound of the class name, PackageStats.class doesn't access system on your phone and find the size of your app, data, and cache files (wish it did). It is used to pull this information (if available) from a parcel, or to take a package and write this information if provided by the package into a parcel.

Using zmarties approach, new File(), is a workable solution.

VikingGlen
  • 1,705
  • 18
  • 18