[英]How to get the name of the application in android?
我想得到我的申請名稱。 我怎么能得到它? 提前致謝。
你可以使用PackageManager#getApplicationInfo()
獲取設備中安裝的所有軟件包的應用程序名稱。 假設您有當前的Context對象ctx
Resources appR = ctx.getResources();
CharSequence txt = appR.getText(appR.getIdentifier("app_name",
"string", ctx.getPackageName()));
您可以使用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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.