Chethan Shetty Chethan Shetty - 1 year ago 253
Android Question

Get app name from package name in android

I'm trying to develop an android app that could list all app's which has cache, I successfully got the information about cache, but now I want to display those app which has some cache in the screen, I have the package name, but problem is how to get the application name from package name,

Let's say package name is

then app name will be

How to achieve this task ?

Please don't mind if this question is silly to you, please help me in solving this riddle,
Thanks in advance.

Answer Source

You need to use PackageManager to get detailed information about installed packages.

PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = null;
try {
    applicationInfo = packageManager.getApplicationInfo(packageName, 0);
} catch (final NameNotFoundException e) {}
final String title = (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");