I want to get the name of my application. How can i get that? Thanks in advance.
-
Are you looking for the label name, the package name, or the apk name? Why do you need this info? – spatulamania Oct 18 '11 at 05:29
-
I am luking for the app name coz I need it at the time of starting the application. – Prachi Oct 18 '11 at 05:38
-
The actual apk file name is arbitrary and shouldn't affect anything. Why is the package name insufficient? – spatulamania Oct 18 '11 at 05:44
4 Answers
You can use PackageItemInfo -> nonLocalizedLabel to get application name.
val applicationName = context.applicationInfo.nonLocalizedLabel.toString()
[Old Answer]
Usually, we do add the application name with app_name string resource, so you can write below code to access the app name
String applicationName = getResources().getString(R.string.app_name);
Reference : Resource Types
But note that, this resource name is not mandatory and can be changed to any other string name. In that case, the code will not work. See the first code snippet which uses PackageItemInfo -> nonLocalizedLabel above for a better solution.

- 81,967
- 29
- 167
- 186
-
@Downvoters Why downvotes here? Why not post a comment about it? Are not you a man? – Pankaj Kumar Sep 17 '14 at 08:08
-
You can use PackageManager
class to obtain ApplicationInfo
:
final PackageManager pm = context.getPackageManager();
ApplicationInfo ai;
try {
ai = pm.getApplicationInfo(packageName, 0);
} catch (final NameNotFoundException e) {
ai = null;
}
final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");
EDIT: CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName,PackageManager.GET_META_DATA));
This would return the application name as defined in <application> tag of its manifest
.

- 108,599
- 23
- 164
- 151
-
I tried this code but it's returning the package name not the application name. – Prachi Oct 18 '11 at 05:34
-
what about for this line, CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA)); – user370305 Oct 18 '11 at 05:40
you can use PackageManager#getApplicationInfo()
For getting the Application Name for all packages installed in the device. Assuming you have your current Context object ctx
Resources appR = ctx.getResources();
CharSequence txt = appR.getText(appR.getIdentifier("app_name",
"string", ctx.getPackageName()));

- 7,226
- 2
- 35
- 40
-
-
-
This makes the assumption that you've defined a resource string "app_name" which will typically be the case, but would only be true because that's the default generated by Android Studio. The resource key of the application label can be whatever you want. You should use `PackageManager.loadApplicationLabel()`. – Jeffrey Blattman Jul 08 '19 at 20:08