Android metadata from manifest returning null
In some cases you need to use getInt()
method:
bundle.getInt("com.google.android.gms.version"));
because the value of this meta-data is defined as an integer.
Log.d("TEST","google: "+bundle.getInt("com.google.android.gms.version"));
For example if the value defined in your meta-data is a String:
<meta-data
android:name="com.elenasys.a"
android:value="abcXJ434" />
use:
bundle.getString("com.elenasys.a"));
if the value is an integer:
<meta-data
android:name="com.elenasys.b"
android:value="1234" />
use getInt()
bundle.getInt("com.elenasys.b"));
Also make sure the tag is under the manifest/application node in AndroidManifest.xml and not just under the root:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.readmetadata"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<meta-data android:name="dbVersion" android:value="1.0" />
<activity android:name=".MainMenu" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
</manifest>