Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7043951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:21:05+00:00 2026-05-28T02:21:05+00:00

public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final

  • 0
public class PackageTabActivity extends ListActivity{
HashMap<String,Object> hm ;
ArrayList<HashMap<String,Object>> applistwithicon ;
  private static final String APP_NAME = "app_name";
  private static final String APP_ICON = "app_icon";
  private static final String APP_SIZE = "app_size";

  Method getPackageSizeInfo = null;
  PackageManager pm  ;
@Override
public void onCreate(Bundle icicle){
    super.onCreate(icicle);
    pm = getPackageManager();

    applistwithicon = new ArrayList<HashMap<String,Object>>();

    try {
        getPackageSizeInfo = pm.getClass().getMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);
    } catch (SecurityException e1) {

        e1.printStackTrace();
    } catch (NoSuchMethodException e1) {

        e1.printStackTrace();
    } 
    new AppDetails().execute();
}

private boolean isSystemPackage(PackageInfo pkgInfo) {
    return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true
            : false;
}


class AppDetails extends AsyncTask<Void, Void, ArrayList<HashMap<String , Object>>>
{
     private  long app_apk_size;
     ProgressDialog mDialog;
     @Override
     public void onPreExecute()
     {
             mDialog = new ProgressDialog(PackageTabActivity.this);
             mDialog.setCancelable(true);
             mDialog.setMessage("Loading... " );
             mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
             mDialog.setProgress(0);
             mDialog.show();
     }
    @Override
    protected ArrayList<HashMap<String, Object>> doInBackground(
            Void... params) {

           ArrayList<HashMap<String,Object>> app = new ArrayList<HashMap<String,Object>>();  

        List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); 

        long []  size = new long[packs.size()];


        for(int i=0;i<packs.size();i++) {

            PackageInfo p = packs.get(i);



            if(!isSystemPackage(p))
            {
                   /*  String package_name = p.applicationInfo.packageName;
                     appname[i] = p.applicationInfo.loadLabel(getPackageManager()).toString();
                     icon[i] = p.applicationInfo.loadIcon(getPackageManager());
                     size[i] = GetSize(package_name);
                 //  Log.v("Test", "app_name = " +appname[i]+"  app_size = "+size[i]);*/


             app= GetSize(p);


           }


        }


             //  


        return app;
    }
    private ArrayList<HashMap<String, Object>> GetSize(final PackageInfo pInfo)
{
try
{
    getPackageSizeInfo.invoke(pm,  pInfo.applicationInfo.packageName, new IPackageStatsObserver.Stub()
    {
        public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException
        {
            app_apk_size= pStats.codeSize/1024;
            if(app_apk_size!=0)
            {
                // If I uncomment-out the below commented-out lines, I get
                // an incorrect result:

                // hm = new HashMap<String, Object>(); 
                // hm.put(APP_SIZE, app_apk_size);
                // hm.put(APP_NAME, pInfo.applicationInfo.loadLabel(pm));
                Log.v("apksize", "appsize = "+app_apk_size+"appname = "+pInfo.applicationInfo.loadLabel(pm));
                // applistwithicon.add(hm);
            }
        }
    });
}
catch(IllegalAccessException e) {}
catch(IllegalArgumentException r) {}
catch(InvocationTargetException w){}
return applistwithicon;
}
    @Override
    public void onPostExecute(ArrayList<HashMap<String, Object>> result)
    {
        mDialog.dismiss();
         CustomAdapterList myAdapter = new CustomAdapterList(result,PackageTabActivity.this );

         setListAdapter(myAdapter);

    }
}

}

But if I uncomment-out the commented-out lines, the wrong result gets logged.

Does anyone know why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:21:06+00:00Added an answer on May 28, 2026 at 2:21 am

    I don’t know what pInfo.applicationInfo.loadLabel(pm) does, but try to put the result in a var instead of calling method twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class Pojo { private String value; public static void printValue() { System.out.println(value= +
public class Bird { private static int id = 0; private String kind; public
public class Sprite { private static final int BMP_COLUMNS = 3; private static final
public class Bird { private static int id = 0; private String kind; public
public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
public class Main3 { public static void main(String[] args) { Integer min = Integer.MIN_VALUE;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.