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

  • SEARCH
  • Home
  • 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 4112636
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:13:16+00:00 2026-05-20T22:13:16+00:00

i got this code off the internet, i suppose to get a list of

  • 0

i got this code off the internet, i suppose to get a list of all the applications on the phone and judging by the comments on the webpage it works but i just cant seem to get it to work for me at all. it seems to be the getPacketManager() that is giving me the problem. can someone please look at the code and explain to me what i have to do to get it working please?

this is my full class… i cant get it to even run, on the 3 locations where there is a “getPackageManager()” it is giving me an error on the left of the screen saying “The method getPackageManager() is undefined for the type getApps”

package cians.app;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class getApps{

class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
    System.out.print(appname + "\\t" + pname + "\\t" + versionName + "\\t"            +versionCode + "\\t");
}
}

private void listPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
    apps.get(i).prettyPrint();
}
}

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();        
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
    PackageInfo p = packs.get(i);
    if ((!getSysPackages) && (p.versionName == null)) {
        continue ;
    }
    PInfo newInfo = new PInfo();
    newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
    newInfo.pname = p.packageName;
    newInfo.versionName = p.versionName;
    newInfo.versionCode = p.versionCode;
    newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
    res.add(newInfo);
}
return res; 
}}
  • 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-20T22:13:17+00:00Added an answer on May 20, 2026 at 10:13 pm

    getPackageManager() is a method of the ‘Context’ class, so you can call it from any object that extends ‘Context’. The class Activity extends context, and your main class extends Activity, so you are able to call getPackageManager() from your main class object. If your class doesn’t extend Context (that’s the case of the getApps class), you can’t call getPackageManager() from it. You’ll need to get your activity context first.

    EDIT:

    OK, you need to pass your activity to this class:

    in getApps class add

    private Context parent = null;
    public getApps(Context _parent) // a constructor that receives the context as parameter
    {
       parent = _parent;
    }
    
    public String getInfo() { // your implementation here... }
    

    and change getPackageManager()... to parent.getPackageManager()...

    in your main activity, create an object of getApps and then call it to get the info:

    getApps appsGetter = new getApps(this); // "this" is your activity actually,which extends Context
    String info = appsGetter.getinfo();
    

    now you still need to implement getInfo(), but it shouldn’t be so hard. and one more thing, classes in Java start with capital letter, so instead getApps consider calling it GetApps or AppsGetter.

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

Sidebar

Related Questions

I've got this code: rs1 = getResults(sSQL1) rs2 = getResults(sSQL2) rs1 and rs2 and
I've got this code in a pair of button click event handlers on a
I've got this code here: SqlCommand CodeStatus = new SqlCommand(SQL, DB); DB.Open(); Reader =
How can I fetch images from a server? I've got this bit of code
I got this doubt while writing some code. Is 'bool' a basic datatype defined
I was given this code a while back. I finally got around to testing
I've got a problem with inheritance and generics. This is the code that illustrates
I got some legacy code that has this: <?PHP if(isset($_GET['pagina'])==homepage) { ?> HtmlCode1 <?php
I've got some code that looks like this: using (DBDataContext dc = new DBDataContext(ConnectionString))
I've got HTML code that roughly looks like this: <li id=someid-11> <img src=... alt=alt

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.