java - Android metadata with manifest file - nullPointerException -


i attempting access metadata activity manifest file.

the manifest looks :

    <activity         android:name="co.uk.benbun.nvrrclubapp.mainactivity"         android:label="@string/app_name" >         <meta-data android:value="newstag" android:name="news"></meta-data>         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> 

the code access it, looks :

    try {         applicationinfo ai = getpackagemanager().getapplicationinfo(this.getpackagename(), packagemanager.get_meta_data);         bundle bundle = ai.metadata;         string myapikey = bundle.getstring("news");     } catch (namenotfoundexception e) {         log.e("metadata", "failed load meta-data, namenotfound: " + e.getmessage());         feedtag = "news";     } catch (nullpointerexception e) {         log.e("metadata", "failed load meta-data, nullpointer: " + e.getmessage());         feedtag = "news";     } 

when execute code nullpointerexception.

what doing wrong?

the documentation packagemanager.get_meta_data says:

componentinfo flag: return metadata data bundles associated component. applies api returning componentinfo subclass.

you calling getapplicationinfo() returns applicationinfo object. applicationinfo not inherit componentinfo, object not have meta-data. need activityinfo mainactivity in order meta-data (activityinfo subclass of componentinfo).


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -