Scripting API

You can manage your Manifest with the Android Manifest Manager using following methods:

Use GetManifest method to get available Android Manifest Template.

  • public static AN_ManifestTemplate GetManifest()

 

Example:

AN_ManifestManager.GetManifest ();

Note: Default Manifest location is 'Assets/Plugins/Android/AndroidManifest.xml'.

 

You can always check if the Manifest already exists in Default location using  getter

AN_ManifestManager.HasManifest

 

 

Use CreateDefaultManifest method to create Default Android Manifest in Default Location.

  • public static void CreateDefaultManifest()

 

Default Unity Manifest content shown below:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
	android:installLocation="preferExternal"
	android:theme="@android:style/Theme.NoTitleBar"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"/>

    <application
		android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:debuggable="true">
        <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
        </activity>
    </application>
</manifest>

 

 

Refresh method  will check if the Manifest file exists in Default Location and if so - read and load it if the file doesn't exist - create Default Manifest in Default Location.

public static void Refresh()

 

Example:

AN_ManifestManager.Refresh();

 

You can iterate through Manifest values using getter of  the AN_ManifestTemplate class.

public Dictionary<string, string> Values

 

Or get value by key

public string GetValue(string key)

 

Example:

foreach (KeyValuePair<string, string> v in manifestTemplate.Values) {
Debug.Log("Key: " v.Key + " Value: " + v.Value);
}

 

To add a new  key and value to Android Manifest use:

public void SetValue(string key, string value)

T

o remove value by its key use:

public void RemoveValue(string key)

 

To iterate through Manifest properties:

public Dictionary<string, List<AN_PropertyTemplate>> Properties

Note: Dictionary key is actually Property Tag. There may be more than one Manifest property with the same Tag.

 

Example:

foreach (string key in template.Properties.Keys) {
    //Iteration through Tags of Property Templates

	foreach (AN_PropertyTemplate p in template.Properties[key]) {
        //Iteration through all Property Templates with the same Tag

		Debug.Log(p.Tag);
	}
}

 

You can get Manifest Properties by various ways:

  • public AN_PropertyTemplate GetOrCreatePropertyWithName(string tag, string name)
  • public AN_PropertyTemplate GetPropertyWithName(string tag, string name)
  • public AN_PropertyTemplate GetOrCreatePropertyWithTag(string tag)
  • public AN_PropertyTemplate GetPropertyWithTag(string tag)
  • public List<AN_PropertyTemplate> GetPropertiesWithTag(string tag)

 

To add the property to Manifest you should create property instance at first and pass it to the method

public void AddProperty(AN_PropertyTemplate property)

 

To remove property from the Manifest use the next method:

public void RemoveProperty(AN_PropertyTemplate property)

 

So, for example if I want to keep Min SDK Version >= 10, here is what we should do:

//Getting the Manifest object
AN_ManifestTemplate Manifest =  AN_ManifestManager.GetManifest();

//Getting the Uses-SDK property
AN_PropertyTemplate UsesSdk =  Manifest.GetPropertyWithTag("uses-sdk");

//Check if Manifest contains this property, and if no create one
if(UsesSdk == null) {
	UsesSdk = Manifest.GetOrCreatePropertyWithTag("uses-sdk");
}


//Keeping Min Sdk Version >= 10
if(UsesSdk.HasKey("android:minSdkVersion")) {
	int version = System.Convert.ToInt32(UsesSdk.GetValue("android:minSdkVersion"));
	if(version < 10) {
		UsesSdk.SetValue("android:minSdkVersion", "10");
	} 
} else {
	UsesSdk.SetValue("android:minSdkVersion", "10");
}

AN_ManifestManager.SaveManifest();

 

 

 

 

AN_ManifestTemplate has AN_ApplicationTemplate getter

public AN_ApplicationTemplate ApplicationTemplate

Application Template data contains all information inside

<application>

...

</application>

XML tag inside Manifest file.

 

Application Template contains collection of all Activity Templates.

You can iterate through Activity Templates collection using getter

public Dictionary<int, AN_ActivityTemplate> Activities

 

 

When the work is done, just save the Manifest using:

public static void SaveManifest()

 

Example:

AN_ManifestManager.SaveManifest();