安卓:获取应用程序的名称(不包名) [英] Android: Get application name (not package name)
本文介绍了安卓:获取应用程序的名称(不包名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表现,我有:
<application
android:name=".MyApp"
android:icon="@drawable/ic_launcher_icon"
android:label="@string/app_name"
android:debuggable="true">
我如何获取标签元素?注:我的code上别人的里面,所以我没有获得@字符串/ APP_NAME
How do I get the label element? Note: My code is running inside of someone else's, so I don't have access to @string/app_name.
推荐答案
这里有一个比其他的答案,这并不要求你明确名称的资源或担心与包名异常简单的方法。
There's an easier way than the other answers that doesn't require you to name the resource explicitly or worry about exceptions with package names.
只要做到:
public static String getApplicationName(Context context) {
int stringId = context.getApplicationInfo().labelRes;
return context.getString(stringId);
}
希望这有助于。
Hope this helps.
这篇关于安卓:获取应用程序的名称(不包名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文