6

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.

KISHORE_ZE
  • 1,466
  • 3
  • 16
  • 26
  • To get a list of installed Apps package name, you can refer to the link http://stackoverflow.com/a/43734832/1252158 – Summved Jain May 02 '17 at 09:50

3 Answers3

16

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

Linh
  • 57,942
  • 23
  • 262
  • 279
Androider
  • 3,833
  • 2
  • 14
  • 24
  • Thanks Androider. I'll try it and let you know. – KISHORE_ZE Aug 31 '15 at 17:29
  • Just give some time. It's getting pretty late here. Will let you know tomorrow – KISHORE_ZE Aug 31 '15 at 17:43
  • 1
    No problems, do as you comforts. – Androider Aug 31 '15 at 17:49
  • I have a small problem. It gives me an error Activity must contain `android.R.id.list` and I practically copy pasted all of that code – KISHORE_ZE Sep 01 '15 at 16:12
  • This is the way to achieve, you can also use link: http://javatechig.com/android/how-to-get-list-of-installed-apps-in-android – Androider Sep 01 '15 at 17:17
  • Ok, maybe it could be my mistake. I'll try it all over again. Unfortunately I won't be having Android Studio right now. I am out of station. And it could even be because of the AIDE mobile developing app I'm using. I'll keep trying in AIDE. But if it doesn't work I'll try it in Android Studio once I get back. Sorry for the delay. – KISHORE_ZE Sep 01 '15 at 17:23
  • Hey, I guess this should answer my question. What with the website and all. But I am guessing my mistake is with the ListAdapter somewhere. But I found another solution, which does not solve the question completely. But at least to some extent. See my answer below. – KISHORE_ZE Sep 01 '15 at 18:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88505/discussion-between-androider-and-kishore-ze). – Androider Sep 01 '15 at 18:05
  • how can I get only the apps installed by the user not the system apps – Jarin Rocks Mar 11 '19 at 08:12
3

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.

Community
  • 1
  • 1
KISHORE_ZE
  • 1,466
  • 3
  • 16
  • 26
3

get appliction icon image from package name

Drawable appicon = getPackageManager().getApplicationIcon("com.example.pkgname");
img.setImageDrawable(appicon);
Makvin
  • 3,475
  • 27
  • 26