直接看代码,
//获取渠道名称
public static String getChannelName(Activity ctx) {
if (ctx == null) {
return null;
}
String channelName = "";
try {
PackageManager packageManager = ctx.getPackageManager();
if (packageManager != null) {
//注意此处为ApplicationInfo 而不是 ActivityInfo,因为友盟设置的meta-data是在application标签中,而不是某activity标签中,所以用ApplicationInfo
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null) {
if (applicationInfo.metaData != null) {
channelName = applicationInfo.metaData.getString("TD_CHANNEL_ID");
}
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return channelName;
}