In my manifest I have:
If not mentioned in the strings.xml/hardcoded in AndroidManifest.xml for whatever reason like android:label="MyApp"
public String getAppLable(Context context) {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = null;
try {
applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0);
} catch (final NameNotFoundException e) {
}
return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown");
}
Or if you know the String resource ID then you can directly get it via
getString(R.string.appNameID);
In Kotlin its simple:
val appLabel = context.applicationInfo.nonLocalizedLabel
public static String getApplicationName(Context context) {
return context.getApplicationInfo().loadLabel(context.getPackageManager());
}
In Kotlin, use the following codes to get Application Name:
// Get App Name
var appName: String = ""
val applicationInfo = this.getApplicationInfo()
val stringId = applicationInfo.labelRes
if (stringId == 0) {
appName = applicationInfo.nonLocalizedLabel.toString()
}
else {
appName = this.getString(stringId)
}
Okay guys another sleek option is
Application.Context.ApplicationInfo.NonLocalizedLabel
verified for hard coded android label on application element.
<application android:label="Big App"></application>
Reference: http://developer.android.com/reference/android/content/pm/PackageItemInfo.html#nonLocalizedLabel
Have you tried using the PackageManager#getActivityInfo()
method? There will be a field that should contain the name of the application.
See the answer to a very similar question here.