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