package com.duben.microtribe.utils

import android.content.Context
import android.content.pm.PackageManager
import android.text.TextUtils

object MateUtils {
    /**
     * 获取application中指定的meta-data
     *
     * @return 如果没有获取成功(没有对应值 ， 或者异常)，则返回值为空
     */
    fun getAppMetaData(ctx: Context?, key: String): String {
        if (ctx == null || TextUtils.isEmpty(key)) {
            return ""
        }
        var resultData=""
        try {
            val packageManager = ctx.packageManager
            if (packageManager != null) {
                val applicationInfo = packageManager.getApplicationInfo(ctx.packageName, PackageManager.GET_META_DATA)
                if (applicationInfo != null) {
                    if (applicationInfo.metaData != null) {
                        resultData = applicationInfo.metaData.getString(key)!!
                    }
                }
            }
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
            return ""
        }
        return resultData
    }
}