Android labelRes is 0

LonsomeHell Source

I am using int stringID = context.getApplicationInfo().labelRes to get the application name resource ID. Then I use context.getString(stringID) to get the application name. I get

 W/ResourceType: No package identifier when getting value for resource number 0x00000000
    android.content.res.Resources$NotFoundException: String resource ID #0x0

Any idea why labelRes is 0?

javaandroidandroid-resources

Answers

answered 3 months ago medbenjemaa #1

try this one it may help you

public static String getApplicationName(Context context) {
    ApplicationInfo applicationInfo = context.getApplicationInfo();
    int stringId = applicationInfo.labelRes;
    return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
}


String appName=getApplicationName(context);

answered 1 month ago LonsomeHell #2

I was able to fix this by specifying the label in strings.xml before the label was passed from the Gradle build file using manifestPlaceholders.

The problem in the third party library is they are not checking if applicationInfo.lableRes is 0.

comments powered by Disqus