ComponentInfo get metadata from manifest?

Put your problem here if it does not fit any of the other categories.

ComponentInfo get metadata from manifest?

Postby yorgosg » Wed Feb 04, 2009 2:23 pm

Hello, I am trying to get the metadata stored in the AndroidManifest.xml

My manifest file is the one below:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.      package="org.android.androidapp"
  6.  
  7.      android:versionCode="1"
  8.  
  9.      android:versionName="1.0.0">
  10.  
  11.         <uses-permission android:name="android.permission.INTERNET"/>
  12.  
  13.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  14.  
  15.     <meta-data
  16.  
  17. android:name="org.android.androidapp.webURL"
  18.  
  19. android:value="http://www.google.com"/>
  20.  
  21.         <activity android:name=".App"
  22.  
  23.                  android:label="@string/app_name">
  24.  
  25.             <intent-filter>
  26.  
  27.                 <action android:name="android.intent.action.MAIN" />
  28.  
  29.                 <category android:name="android.intent.category.LAUNCHER" />
  30.  
  31.             </intent-filter>
  32.  
  33.         </activity>
  34.  
  35.     </application>
  36.  
  37. </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



and the code in my onCreate() is the one below:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        ComponentInfo ci = new ComponentInfo();
  2.  
  3.        
  4.  
  5.         PackageManager pm = getPackageManager();
  6.  
  7.        
  8.  
  9.         XmlResourceParser myParser = ci.loadXmlMetaData(pm, "org.android.androidapp.webURL");
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Unfortunately, the myParser value gets a null value...

Does anyone know what I am doing wrong? Please help, this is urgent..

I also tried the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Bundle b = ci.metaData;
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


but this also returns null...

Whats the correct syntax of things for me to get the metadata value (the webUrl stored in my metadata)

any help would be highly appreciated!!
yorgosg
Developer
Developer
 
Posts: 35
Joined: Wed Jan 30, 2008 9:53 am

Top

Postby jez0o0z » Sat Mar 07, 2009 3:50 am

Try this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3. ActivityInfo  ai = getPackageManager().getActivityInfo(this.getComponentName(), PackageManager.GET_META_DATA);
  4.  
  5. Bundle bundle = ai.metaData;
  6.  
  7. String value = (String)bundle.get("org.android.androidapp.webURL");
  8.  
  9. Log.d(LOG_TAG, "value =" +  value);
  10.  
  11.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Also, I think your metadata tag needs to be under <Activity> not under <Application>
I just started playing with this, and this seems to work, but I'll have a better look at it next week.
jez0o0z
Freshman
Freshman
 
Posts: 3
Joined: Sat Mar 07, 2009 2:17 am

Postby jaouad » Wed Apr 22, 2009 3:37 pm

You can also use meta-data in the application tag in the manifest like this:
try {
ApplicationInfo ai;

ai = getPackageManager().getApplicationInfo(this.getComponentName().getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = ai.metaData;
String value = (String)bundle.get("zoo");
System.out.println("zoo =" + value);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
jaouad
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Oct 22, 2008 10:26 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 11 guests