Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the name, icon and package name of all the installed applications in android

I want to be able to get the string package name and icon of all the applications installed in my phone. What I have done: Browsed and found this solution

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
            final List pkgAppsList = this.getPackageManager().queryIntentActivities(mainIntent, 0);
            for(int counter = 0; counter<=pkgAppsList.size()-1;counter++)
            {
                    Log.e("TAG", pkgAppsList.get(counter).toString());
  } 

The problem is that it displays package and class name as as a as a mix and I can't get the icon. What I want is to show the user a list of all the applications installed on the phone with the icon. And I also need to be able to get the package name with a List.OnItemClickListener. I assume that using an array of app names and package name which are of same positioning I can do that. But how would I get the app icon and name with package name. Preferably as an Array or ArrayList that I can convert into a listView object. If there is any alternative method even let me know. I am still a beginner in Android.

And please do help.

like image 465
KISHORE_ZE Avatar asked Aug 31 '15 16:08

KISHORE_ZE


3 Answers

Please use the below code and directions:

//check this code with some hard work then you will rock
 List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);

    ArrayList<AppInfo> res = new ArrayList<AppInfo>();
    for(int i=0;i<apps.size();i++) {
                    PackageInfo p = apps.get(i);

                    AppInfo newInfo = new AppInfo();
                    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);
                    }
                }

    class AppInfo {
        String appname = "";
        String pname = "";
        String versionName = "";
        int versionCode = 0;
        Drawable icon;

    }

For more information try these links: http://javatechig.com/android/how-to-get-list-of-installed-apps-in-android http://developer.android.com/reference/android/content/pm/PackageManager.html

like image 116
Androider Avatar answered Oct 14 '22 23:10

Androider


Using this link from this question. I got the package name. Then using the answer from this question I got the package/app icon. Now as soon as I figure the array adapter to accommodate this. I guess its done then.

My Code:

final PackageManager pm = getPackageManager();
List<applicationinfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
//The log is not required so if you want to and I recommend during release you remove that statement.
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Drawable icon = getPackageManager().getApplicationIcon(packageInfo.packageName)
imageView.setImageDrawable(icon);

Hope this helps all readers as well.

like image 25
KISHORE_ZE Avatar answered Oct 14 '22 22:10

KISHORE_ZE


get appliction icon image from package name

Drawable appicon = getPackageManager().getApplicationIcon("com.example.pkgname");
img.setImageDrawable(appicon);
like image 33
Makvin Avatar answered Oct 15 '22 00:10

Makvin