赞
踩
一篇关于meta-data的转载记录
<application ... >
<meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</application>
try {
ApplicationInfo info = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
Log.e("info", info.metaData.getString("TEST_KEY"));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
<activity ... >
<meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</activity>
try {
ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
Log.e("info", info.metaData.getString("TEST_KEY"));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
<service ... >
<meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</service>
try {
ServiceInfo info = getPackageManager().getServiceInfo(getComponentName(), PackageManager.GET_META_DATA);
Log.e("info", info.metaData.getString("TEST_KEY"));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
<receiver ... >
<meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</receiver>
try {
ActivityInfo info = getPackageManager().getReceiverInfo(getComponentName(), PackageManager.GET_META_DATA);
Log.e("info", info.metaData.getString("TEST_KEY"));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
在build.gradle的多版本中设置
manifestPlaceholders = ["test_key": "修改的内容"]
好比如下
productFlavors{
dev{
manifestPlaceholders = ["test_key": "测试版key"]
}
free{
applicationIdSuffix ".free"
manifestPlaceholders = ["test_key": "Free版key"]
}
}
效果如下
[Android获取Manifest中元素的值](http://blog.csdn.net/xx326664162/article/details/50727941)
[使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中变量的值](http://blog.csdn.net/xx326664162/article/details/49247815)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。