Gets the application name specified by android:label in the AndroidManifest.xml. - Android App

Android examples for App:APK File

Description

Gets the application name specified by android:label in the AndroidManifest.xml.

Demo Code


//package com.java2s;

import android.content.Context;

import android.support.annotation.NonNull;

public class Main {
    /**/*from   w  w w.ja v a 2 s  .c o m*/
     * Gets the application name specified by android:label in the AndroidManifest.xml.
     * It does not work if you hard-code your app name like android:label="MyApp".
     * Use a string resource such as @string/app_name.
     * @param context the context
     * @return application name
     */
    public static String getApplicationName(@NonNull Context context) {
        int stringId = context.getApplicationInfo().labelRes;
        return context.getString(stringId);
    }
}

Related Tutorials