Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Android Bug: Bad Returns on Meta-data Information

DZone's Guide to

Android Bug: Bad Returns on Meta-data Information

Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

Inside any AndroidManifest.xml file, it is possible to add useful meta-data for applications. I could put basic information like author name, application version and so on.

<meta-data android:name="author" android:value="John Doe" />
<meta-data android:name="serverMinVersion" android:value="6.1.1" />

Inside my application about activity, I want to show this info.

ApplicationInfo aInfo = getPackageManager().getApplicationInfo(
                 getPackageName(), PackageManager.GET_META_DATA);
String authorName = aInfo.metaData.getString("author");
String serverMinVersion = aInfo.metaData.getString("serverMinVersion");
// show this info
 But something happened after I changed the version through an upgrade.

<meta-data android:name="serverMinVersion" android:value="6.2" />

Suddenly, the version shown inside about info was null.

At first I thought I may have mistyped, and then that I changed something. But, after a while, I realized that it's not my problem, but an Android bug. I saw that a value like 6.2a is working without a problem. Looking for similarities, I found this bug, which tells that the getString() method on metaData for something with only numeric values always returns null.

Before finding this bug, it wasn't obvious to me that there is a difference between 6.1.1 and 6.2 . 6.1.1 cannot be considered a number, while 6.2 is one.

The solution, as told inside the bug link, was to get the value like this:

String serverMinVersion = aInfo.metaData.get("serverMinVersion").toString();
This is just a small bug inside the Android beast, and given that it has been three years since it was reported and no one did anything, I can just give a thumb down to Android.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}