/**
* 获取当前渠道名称
*
* @return
*/
public static String getUmChannel() {
Application context = AnguoUtils.getContext();
//友盟没有初始化的时候返回空
String channel = AnalyticsConfig.getChannel(context);
if (TextUtils.isEmpty(channel)) {
channel = ManifestUtils.INSTANCE.getMetadata(context, "UMENG_CHANNEL");
}
return channel;
}
package com.anguomob.total.utils
import android.content.Context
import android.content.pm.PackageManager
/**
* Create by: liuan
* Create date: 2020-10-29 0029
* Describe:
*/
object ManifestUtils {
fun getMetadata(context: Context, key: String?): String {
try {
val metaData = context.packageManager
.getApplicationInfo(context.packageName,
PackageManager.GET_META_DATA).metaData
if (metaData != null && metaData.size() > 0 && metaData.containsKey(key)) {
return metaData[key].toString()
}
return ""
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
return ""
}
fun getPackageName(context: Context): String {
try {
return context.packageManager.getPackageInfo(
context.packageName, 0).packageName
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
return ""
}
}