How Android gets Umeng channel information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.