开发者

Finding the "name" of your Android application

Is there any way to (programatically) find out what your app's name is? I'm specifically talking about the android:label property from the application tag in the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0">
    <application android:label="THIS THING HERE!" android:icon="@drawable/icon">
开发者_StackOverflow中文版        <!-- ... -->
    </application>
</manifest> 


I found a way to do it... seems a little obtuse though:

getPackageManager().getApplicationLabel(getApplicationInfo())


If android:label is set to use a string resource such as:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <!-- ... -->
    </application>
</manifest> 

Then you can do:

getString(R.string.app_name)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜