Chethan Shetty Chethan Shetty - 4 months ago 121
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

com.android.browser

then app name will be
Browser


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

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