1

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? Maybe populating it somehow at compile time?

I currently have the following on my 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.

3
  • I think you can't change meta-data value at runtime AFAIK Commented Mar 29, 2017 at 20:13
  • Possible duplicate of Changing manifest meta-data from code Commented Mar 29, 2017 at 20:14
  • @Shubham The first thing i wrote "I understand the AndroidManifest.xml is prepared at compile time and not runtime," I'm looking for an alternative, I believe i read somewhere that its possible to assign the value at compile time but still not hard coding it... Commented Mar 29, 2017 at 20:17

1 Answer 1

3

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.

Example:

android {
    defaultConfig {
        manifestPlaceholders = [hostName:"www.example.com"]
    }
    ...
}

<intent-filter ... >
    <data android:scheme="http" android:host="${hostName}" ... />
    ...
</intent-filter>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.