对应Manifest文件中的Umeng渠道
<meta-data android:name="UMENG_CHANNEL"android:value="${UMENG_CHANNEL_VALUE}" />
注意UMENG_CHANNEL_VALUE
前后的是大括号{}
AndroidStudio3.0上进行多渠道打包必须指定一种 flavor dimensions
flavorDimensions "default"
productFlavors {
HuanStore {
dimension "default"
}
huanhelper {
dimension "default"
}
tvhuan {
dimension "default"
}
dangbei {
dimension "default"
}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
获取meta-data的value
//通过ApplicationInfo获取meta-data标签中指定name对应的value
private String getMetaValue(String name) {
String value = null;
try {
ApplicationInfo appInfo = this.getPackageManager()
.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
value = appInfo.metaData.getString(name);
Log.d(TAG,name + "-->" + value);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return value;
}
通过ActivityInfo获取
ActivityInfo info = this.getPackageManager()
.getActivityInfo(getComponentName(),PackageManager.GET_META_DATA);
info.metaData.getString("meta_name");
通过ServiceInfo获取
ComponentName cn = new ComponentName(this, MetaDataService.class);
ServiceInfo info = this.getPackageManager().getServiceInfo(cn, PackageManager.GET_META_DATA);
info.metaData.getString("meta_name");
通过ReceiverInfo获取
ComponentName cn = new ComponentName(context, MetaDataReceiver.class);
ReceiverInfo info = context.getPackageManager().getReceiverInfo(cn, PackageManager.GET_META_DATA);
info.metaData.getString("meta_name");
网友评论