find the APK size of installed applications

前端 未结 2 1109
挽巷
挽巷 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);
            }
        });
    
    0 讨论(0)
  • 2021-02-11 10:25
    ApplicationInfo tmpInfo = context.getPackageManager().getApplicationInfo(packageName,-1);
    long size = new File(tmpInfo.sourceDir).length();
    
    0 讨论(0)
提交回复
热议问题