Unity 添加 AndroidManifest.xml节点内容

首先添加所需要的xml的命名空间;

using System.Xml;

通过代码,按照需求,进行相应的修改;

    void FixedManifestXml() {
        string path = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(path);

        XmlNode root = xmlDocument.DocumentElement;
        string namespaceURI = root.GetNamespaceOfPrefix("android");

        var node_manifest = xmlDocument["manifest"];
        var node_application = node_manifest["application"];

        //------------ add node start ------------
        var receiver = xmlDocument.CreateElement("receiver");
        receiver.SetAttribute("name", namespaceURI, "com.xxx.xxx.xxx");
        receiver.SetAttribute("exported", namespaceURI, "true");

        var filter = xmlDocument.CreateElement("intent-filter");
        var action = xmlDocument.CreateElement("action");
        action.SetAttribute("name", namespaceURI, "xxx.xxx.xxx.xxx");
        filter.AppendChild(action);
        receiver.AppendChild(filter);
        node_application.AppendChild(receiver);
        //------------ add node end ------------

        xmlDocument.Save(path);
    }

这样就可以完成简单的添加节点的操作了

你可能感兴趣的:(Unity3D随笔)