package cn.finalteam.toolsfinal;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Desction:Android Manifest工具类
 * Author:pengjianbo
 * Date:15/9/17 下午4:38
 */
public class ManifestUtils {

    /**
     * 获得渠道号
     * @param context
     * @param channelKey
     * @return
     */
    public static String getChannelNo(Context context, String channelKey) {
        String name = context.getPackageName();
        ApplicationInfo appInfo;
        String msg = "";
        try {
            appInfo = context.getPackageManager().getApplicationInfo(name,
                    PackageManager.GET_META_DATA);
            msg = appInfo.metaData.getString(channelKey);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        if (StringUtils.isEmpty(msg)) {
            return "";
        }

        return msg;
    }

    /**
     * 获得apk版本号
     * @param context
     * @return
     */
    public static String getVersionName(Context context) {
        String version = "";
        // 获取packagemanager的实例
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(),
                    0);
            version = packInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        if (StringUtils.isEmpty(version)) {
            version = "";
        }

        return version;
    }

    /**
     * 获得apk版本号
     * @param context
     * @return
     */
    public static int getVersionCode(Context context) {
        int versionCode = 0;
        // 获取packagemanager的实例
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(),
                    0);
            versionCode = packInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return versionCode;
    }
}

@@ -318,12 +318,27 @@
  * %E8%8E%B7
-%E5%BE%97%E6%B8%A0%E9%81%93%E5%8F%B7
+%E5%8F%96Manifest Meta Data
 %0A   
@@ -370,23 +370,20 @@
  @param 
-channel
+meta
 Key%0A    
@@ -433,17 +433,16 @@
  get
-ChannelNo
+MetaData
 (Con
@@ -462,23 +462,20 @@
  String 
-channel
+meta
 Key) %7B%0A 
@@ -768,15 +768,12 @@
 ing(
-channel
+meta
 Key)
@@ -970,32 +970,255 @@
 urn msg;%0A    %7D%0A%0A
+    /**%0A     * %E8%8E%B7%E5%BE%97%E6%B8%A0%E9%81%93%E5%8F%B7%0A     * @param context%0A     * @param channelKey%0A     * @return%0A     */%0A    public static String getChannelNo(Context context, String channelKey) %7B%0A        return getMetaData(context, channelKey);%0A    %7D%0A%0A
     /**%0A     * %E8%8E%B7

添加获取menifest meta data值方法