我想获取我的应用程序的名称。我怎么能得到它? 提前谢谢。
答案 0 :(得分:10)
答案 1 :(得分:4)
您可以使用PackageManager#getApplicationInfo()
获取设备中安装的所有软件包的应用程序名称。 假设您有当前的Context对象ctx
Resources appR = ctx.getResources();
CharSequence txt = appR.getText(appR.getIdentifier("app_name",
"string", ctx.getPackageName()));
答案 2 :(得分:3)
您可以使用PackageManager
课程来获取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)");
编辑:CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName,PackageManager.GET_META_DATA));
这将是return the application name as defined in <application> tag of its manifest
。
答案 3 :(得分:0)