[英]How to populate AndroidManifest meta-data value programatically?
I understand the AndroidManifest.xml
is prepared at compile time and not runtime , is there any other way to populate metadata in the manifest without relying on hard coded strings? 我知道
AndroidManifest.xml
是在编译时而不是在运行时准备的 ,是否有其他方法可以在不依赖硬编码字符串的情况下在清单中填充元数据? Maybe populating it somehow at compile time? 也许在编译时以某种方式填充它?
I currently have the following on my AndroidManifest.xml
我目前在
AndroidManifest.xml
具有以下内容
<application
android:allowBackup="true"
android:icon="@drawable/dt_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<meta-data
android:name="DataPath"
android:value=""
/> ...
I don't want to hard code the value and instead populate it somehow with the results from: 我不想对值进行硬编码,而是用来自以下位置的结果以某种方式填充它:
Environment.getExternalStorageDirectory()
Another application will later retrieve the value of DataPath
by utilizing the ApplicationInfo
's metaData property. 另一个应用程序稍后将通过利用
ApplicationInfo
的metaData属性来检索DataPath
的值。
I believe i read somewhere that its possible to assign the value at compile time but still not hard coding it
我相信我在某处读到它可以在编译时分配值,但仍不能对其进行硬编码
The best you can do is to assign a value from gradle via manifest placeholders . 最好的办法是通过清单占位符从gradle中分配一个值。
Example: 例:
android {
defaultConfig {
manifestPlaceholders = [hostName:"www.example.com"]
}
...
}
<intent-filter ... >
<data android:scheme="http" android:host="${hostName}" ... />
...
</intent-filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.