Ejemplo n.º 1
0
        public static void UpdateManifest(string fullPath)
        {
            string appId = FacebookSettings.AppId;

            if (!FacebookSettings.IsValidAppId)
            {
                Debug.LogError("You didn't specify a Facebook app ID.  Please add one using the Facebook menu in the main Unity editor.");
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(fullPath);

            if (doc == null)
            {
                Debug.LogError("Couldn't load " + fullPath);
                return;
            }

            XmlNode manNode = FindChildNode(doc, "manifest");
            XmlNode dict    = FindChildNode(manNode, "application");

            if (dict == null)
            {
                Debug.LogError("Error parsing " + fullPath);
                return;
            }

            string ns = dict.GetNamespaceOfPrefix("android");

            // add the unity login activity
            XmlElement unityLoginElement = CreateUnityOverlayElement(doc, ns, UnityLoginActivityName);

            ManifestMod.SetOrReplaceXmlElement(dict, unityLoginElement);

            // add the unity dialogs activity
            XmlElement unityDialogsElement = CreateUnityOverlayElement(doc, ns, UnityDialogsActivityName);

            ManifestMod.SetOrReplaceXmlElement(dict, unityDialogsElement);

            ManifestMod.AddAppLinkingActivity(doc, dict, ns, FacebookSettings.AppLinkSchemes[FacebookSettings.SelectedAppIndex].Schemes);

            ManifestMod.AddSimpleActivity(doc, dict, ns, DeepLinkingActivityName, true);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameRequestActivityName);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupCreateActivityName);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupJoinActivityName);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityAppInviteDialogActivityName);

            // add the app id
            // <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ fb<APPID>" />
            XmlElement appIdElement = doc.CreateElement("meta-data");

            appIdElement.SetAttribute("name", ns, ApplicationIdMetaDataName);
            appIdElement.SetAttribute("value", ns, "fb" + appId);
            ManifestMod.SetOrReplaceXmlElement(dict, appIdElement);

            // Add the facebook content provider
            // <provider
            //   android:name="com.facebook.FacebookContentProvider"
            //   android:authorities="com.facebook.app.FacebookContentProvider<APPID>"
            //   android:exported="true" />
            XmlElement contentProviderElement = CreateContentProviderElement(doc, ns, appId);

            ManifestMod.SetOrReplaceXmlElement(dict, contentProviderElement);

            // Remove the FacebookActivity since we can rely on it in the androidsdk aar as of v4.12
            // (otherwise unity manifest merge likes fail if there's any difference at all)
            XmlElement facebookElement;

            if (TryFindElementWithAndroidName(dict, FacebookActivityName, out facebookElement))
            {
                dict.RemoveChild(facebookElement);
            }

            // Save the document formatted
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent          = true,
                IndentChars     = "  ",
                NewLineChars    = "\r\n",
                NewLineHandling = NewLineHandling.Replace
            };

            using (XmlWriter xmlWriter = XmlWriter.Create(fullPath, settings))
            {
                doc.Save(xmlWriter);
            }
        }
Ejemplo n.º 2
0
        public static void UpdateManifest(string fullPath)
        {
            //string appId = FacebookSettings.AppId;

            //if (!FacebookSettings.IsValidAppId)
            //{
            //    Debug.LogError("You didn't specify a Facebook app ID.  Please add one using the Facebook menu in the main Unity editor.");
            //    return;
            //}

            XmlDocument doc = new XmlDocument();

            doc.Load(fullPath);

            if (doc == null)
            {
                Debug.LogError("Couldn't load " + fullPath);
                return;
            }

            XmlNode manNode = FindChildNode(doc, "manifest");
            XmlNode dict    = FindChildNode(manNode, "application");

            if (dict == null)
            {
                Debug.LogError("Error parsing " + fullPath);
                return;
            }

            string ns = dict.GetNamespaceOfPrefix("android");

            // add the unity login activity
            XmlElement unityLoginElement = CreateUnityOverlayElement(doc, ns, UnityLoginActivityName);

            ManifestMod.SetOrReplaceXmlElement(dict, unityLoginElement);

            // add the unity dialogs activity
            XmlElement unityDialogsElement = CreateUnityOverlayElement(doc, ns, UnityDialogsActivityName);

            ManifestMod.SetOrReplaceXmlElement(dict, unityDialogsElement);

            // add the login activity
            XmlElement loginElement = CreateLoginElement(doc, ns);

            ManifestMod.SetOrReplaceXmlElement(dict, loginElement);

            //ManifestMod.AddAppLinkingActivity(doc, dict, ns, FacebookSettings.AppLinkSchemes[FacebookSettings.SelectedAppIndex].Schemes);

            ManifestMod.AddSimpleActivity(doc, dict, ns, DeepLinkingActivityName, true);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameRequestActivityName);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupCreateActivityName);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityGameGroupJoinActivityName);
            ManifestMod.AddSimpleActivity(doc, dict, ns, UnityAppInviteDialogActivityName);

            // add the app id
            // <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ fb<APPID>" />
            XmlElement appIdElement = doc.CreateElement("meta-data");

            appIdElement.SetAttribute("name", ns, ApplicationIdMetaDataName);
            //appIdElement.SetAttribute("value", ns, "fb" + appId);
            ManifestMod.SetOrReplaceXmlElement(dict, appIdElement);

            // Add the facebook content provider
            // <provider
            //   android:name="com.facebook.FacebookContentProvider"
            //   android:authorities="com.facebook.app.FacebookContentProvider<APPID>"
            //   android:exported="true" />
            //XmlElement contentProviderElement = CreateContentProviderElement(doc, ns, appId);
            //ManifestMod.SetOrReplaceXmlElement(dict, contentProviderElement);

            // Add the facebook activity
            // <activity
            //   android:name="com.facebook.FacebookActivity"
            //   android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            //   android:label="@string/app_name"
            //   android:theme="@android:style/Theme.Translucent.NoTitleBar" />
            XmlElement facebookElement = CreateFacebookElement(doc, ns);

            ManifestMod.SetOrReplaceXmlElement(dict, facebookElement);

            // Save the document formatted
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent          = true,
                IndentChars     = "  ",
                NewLineChars    = "\r\n",
                NewLineHandling = NewLineHandling.Replace
            };

            using (XmlWriter xmlWriter = XmlWriter.Create(fullPath, settings))
            {
                doc.Save(xmlWriter);
            }
        }