4

Is there any way to pull an ApplicationInfo object from the PackageManager? I have tried many different types of methods to achieve this, but to no avail. I'm currently working on the default android launcher screen (Application Drawer) and would like to get package information specifically from a package name. This is not at the application layer, but at the build layer of the Launcher2 Application, the source. The version of android that I am working with is 2.3.3 .

Here is what I have tried:

ApplicationInfo item = pack.getApplicationInfo(package_list.get(i), PackageManager.GET_ACTIVITIES);

Error:

Type mismatch: cannot convert from android.content.pm.ApplicationInfo to com.android.launcher2.ApplicationInfo

This is not for retrieving the current package running, but ALL applications on the phone itself.

I found that:

pack.getApplicationInfo(packageName, flags)

Does not return the same ApplicationInfo object as the ApplicationInfo passed into the function below in the AllApps2D.java:

public void addApps(ArrayList<ApplicationInfo> list)

I am trying to pull the ApplicationInfo object from the package itself with just the name.

The function in question is below, as found in the open source code of AllApps2D.java (Launcher2 Folder)

 private ArrayList<ApplicationInfo> mAllAppsList = new ArrayList<ApplicationInfo>();

 public void addApps(ArrayList<ApplicationInfo> list) {
        final int N = list.size();

        for (int i=0; i<N; i++) {
            final ApplicationInfo item = list.get(i);
            int index = Collections.binarySearch(mAllAppsList, item,
                    LauncherModel.APP_NAME_COMPARATOR);
            if (index < 0) {
                index = -(index+1);
            }
            mAllAppsList.add(index, item);
        }
        mAppsAdapter.notifyDataSetChanged();
    }

UPDATE

Basically what I'm trying to do is reorder the arrangement of icons in the launcher with a custom order. It would be ideal if I could retrieve the information necessary for this via the PackageManager.

In order for what I have implemented to work, I have to be able to pull the SAME ApplicationInfo object that the AllApps2D code is using, which is apparently:

com.android.Launcher2.ApplicationInfo

Which is not the same as what is returned by:

ApplicationInfo item = pack.getApplicationInfo(package_list.get(i), PackageManager.GET_ACTIVITIES);

which is:

android.content.pm.ApplicationInfo

The code available for the launcher, and the class I'm working with is found here .

None of these techniques work WITHIN the launcher2 application within a android build. Are there any other suggestions?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
JoxTraex
  • 13,423
  • 6
  • 32
  • 45

2 Answers2

7

If you want to get all applications, do this:

import android.content.pm.ApplicationInfo;

...

List<ApplicationInfo> apps = context.getPackageManager().getInstalledApplications(0);

Information about a single application (given that you know its manifest package name), is done line this:

import android.content.pm.ApplicationInfo;

...

ApplicationInfo app = context.getPackageManager().getApplicationInfo(packageName, 0);
Reno
  • 33,594
  • 11
  • 89
  • 102
hackbod
  • 90,665
  • 16
  • 140
  • 154
  • Already tried this, they are not the same object in the Launcher2 Application and you cannot cast them. – JoxTraex Jun 21 '11 at 01:02
  • any other suggestions ? I'm kind of stuck and not sure how to handle this. – JoxTraex Jun 21 '11 at 17:35
  • They are absolutely the same object. Maybe Launcher2 has its own class named ApplicationInfo. If so... well, DON'T USE THAT. Use my code, which is explicitly important the platform's android.content.pm.ApplicationInfo. – hackbod Jun 23 '11 at 13:33
  • 1
    Here's a suggestion: stop doing this in the Launcher2 code. Write a small test app that does this. I think you are causing yourself trouble because you are trying to do stuff in a big existing code base that you don't understand. – hackbod Jun 23 '11 at 13:34
  • The method getApplicationInfo() is deprecated on Android 13. What is alternative? – Bokili Production Sep 15 '22 at 18:51
0
           ArrayList<PInfo> res = new ArrayList<PInfo>();
    final PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm
            .getInstalledApplications(PackageManager.GET_META_DATA);
    appName = new String[packages.size()];
    for (ApplicationInfo packageInfo : packages) {
    appName[count] = packageInfo.loadLabel(getPackageManager()).toString();
    count++;
    }

The above code use for getting all the information about installed application in the android device like version,logo,app name,package name ,permission and all thenk about an installed app.

DynamicMind
  • 4,240
  • 1
  • 26
  • 43
  • Already tried this, they are not the same object in the Launcher2 Application and you cannot cast them. Any other suggestions? – JoxTraex Jun 21 '11 at 17:34