Today I want to get the value of umeng_channal in the manifest file, but when Debug, it always returns NULL.
<meta-data android:name= "Umeng_channel" android:value= "test"/>
The General method:
<span style= "FONT-SIZE:18PX;" >/** * Get Channel name * @param CTX HERE The habitual setting is activity, in fact the context can be * @return if not successful, then the return value is empty */public Stati C String Getchannelname (Activity ctx) {if (CTX = = null) {return null; } String channelname = null; try {Packagemanager Packagemanager = Ctx.getpackagemanager (); if (Packagemanager! = null) {//note here is ApplicationInfo instead of Activityinfo, because the Meta-data set by the Allies is in the application tag, not a Activity tab, so use applicationinfo applicationinfo applicationinfo = Packagemanager.getapplicationinfo (Ctx.getP Ackagename (), packagemanager.get_meta_data); if (applicationinfo! = null) {if (applicationinfo.metadata! = null) {Channelna me = ApplicationInfo.metaData.getString (""); }}}} catch (Packagemanager.namenotfoundexception e) {e.printstacktrace (); } return channelname; }</span>
after extraction:
<span style= "FONT-SIZE:18PX;" >/** * Gets the Meta-data specified in application * @return If there is no success (no corresponding value, or exception), the return value is empty */public static String getappm Etadata (Context ctx, String key) {if (CTX = = NULL | | Textutils.isempty (key)) {return null; } String resultdata = null; try {Packagemanager Packagemanager = Ctx.getpackagemanager (); if (Packagemanager! = null) {ApplicationInfo applicationinfo = Packagemanager.getapplicationinfo (ctx.getPa Ckagename (), packagemanager.get_meta_data); if (applicationinfo! = null) {if (applicationinfo.metadata! = null) {Resultdat A = applicationInfo.metaData.getString (key); }}}} catch (Packagemanager.namenotfoundexception e) {e.printstacktrace (); } return resultdata; }</span>
Summary:
Print out the channel information in debug mode! But you can print out the information in the released version!
How Android gets Umeng channel information