find the APK size of installed applications

前端 未结 2 1104
挽巷
挽巷 2021-02-11 09:52

I am trying to calculate apk file size of the installed applications. Here is the code

 public class PackageTabActivity extends ListActivity{

  private static f         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-11 10:11

    Here is a hack from Joseph that worked for me. His original post can be found here

    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);
            }
        });
    

提交回复
热议问题