From 6f9fd74a57402f38947310e0523916b377b283dc Mon Sep 17 00:00:00 2001 From: CodeMasterYi Date: Fri, 10 Feb 2023 10:33:30 +0800 Subject: [PATCH] [Deeplink] Android URL Schemes Addition revise 1. `host` is allowed. write it in `README.md` 2. URL Schemes insertion is not very ok, when there is multiple schemes. https://developer.android.com/training/app-links/deep-linking --- .../Adjust/Editor/AdjustEditorPreprocessor.cs | 38 ++++++++----------- README.md | 2 +- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Assets/Adjust/Editor/AdjustEditorPreprocessor.cs b/Assets/Adjust/Editor/AdjustEditorPreprocessor.cs index 0c8d9b14..fa4ab144 100644 --- a/Assets/Adjust/Editor/AdjustEditorPreprocessor.cs +++ b/Assets/Adjust/Editor/AdjustEditorPreprocessor.cs @@ -117,7 +117,6 @@ private static bool AddURISchemes(XmlDocument manifest) var intentRoot = manifest.DocumentElement.SelectSingleNode("/manifest/application/activity[@android:name='com.unity3d.player.UnityPlayerActivity']", GetNamespaceManager(manifest)); var usedIntentFiltersChanged = false; - var usedIntentFilters = GetIntentFilter(manifest); foreach (var uriScheme in AdjustSettings.AndroidUriSchemes) { Uri uri; @@ -141,6 +140,7 @@ private static bool AddURISchemes(XmlDocument manifest) if (!IsIntentFilterAlreadyExist(manifest, uri)) { + var usedIntentFilters = GetIntentFilter(manifest); Debug.Log("[Adjust]: Adding new URI with scheme: " + uri.Scheme + ", and host: " + uri.Host); var androidSchemeNode = manifest.CreateElement("data"); AddAndroidNamespaceAttribute(manifest, "scheme", uri.Scheme, androidSchemeNode); @@ -148,41 +148,33 @@ private static bool AddURISchemes(XmlDocument manifest) usedIntentFilters.AppendChild(androidSchemeNode); usedIntentFiltersChanged = true; + intentRoot.AppendChild(usedIntentFilters); + Debug.Log(string.Format("[Adjust]: Android deeplink URI scheme \"{0}\" successfully added to your app's AndroidManifest.xml file.", uriScheme)); } } - if (usedIntentFiltersChanged && usedIntentFilters.ParentNode == null) - { - intentRoot.AppendChild(usedIntentFilters); - } - return usedIntentFiltersChanged; } private static XmlElement GetIntentFilter(XmlDocument manifest) { - var xpath = "/manifest/application/activity/intent-filter[data/@android:scheme and data/@android:host]"; - var intentFilter = manifest.DocumentElement.SelectSingleNode(xpath, GetNamespaceManager(manifest)) as XmlElement; - if (intentFilter == null) - { - const string androidName = "name"; - const string category = "category"; + const string androidName = "name"; + const string category = "category"; - intentFilter = manifest.CreateElement("intent-filter"); + var intentFilter = manifest.CreateElement("intent-filter"); - var actionElement = manifest.CreateElement("action"); - AddAndroidNamespaceAttribute(manifest, androidName, "android.intent.action.VIEW", actionElement); - intentFilter.AppendChild(actionElement); + var actionElement = manifest.CreateElement("action"); + AddAndroidNamespaceAttribute(manifest, androidName, "android.intent.action.VIEW", actionElement); + intentFilter.AppendChild(actionElement); - var defaultCategory = manifest.CreateElement(category); - AddAndroidNamespaceAttribute(manifest, androidName, "android.intent.category.DEFAULT", defaultCategory); - intentFilter.AppendChild(defaultCategory); + var defaultCategory = manifest.CreateElement(category); + AddAndroidNamespaceAttribute(manifest, androidName, "android.intent.category.DEFAULT", defaultCategory); + intentFilter.AppendChild(defaultCategory); - var browsableCategory = manifest.CreateElement(category); - AddAndroidNamespaceAttribute(manifest, androidName, "android.intent.category.BROWSABLE", browsableCategory); - intentFilter.AppendChild(browsableCategory); - } + var browsableCategory = manifest.CreateElement(category); + AddAndroidNamespaceAttribute(manifest, androidName, "android.intent.category.BROWSABLE", browsableCategory); + intentFilter.AppendChild(browsableCategory); return intentFilter; } diff --git a/README.md b/README.md index bb515f36..672eb791 100644 --- a/README.md +++ b/README.md @@ -310,7 +310,7 @@ What iOS post-build process will perform under the hood will be swizzling of som ### Deeplink handling in Android apps -In order to set up deeplinking support for Android platform, make sure to add all the schemes you would like your app to handle into the `Android URI Schemes` list. **Note:** Pay attention to tooltip which says that when you are entering URI schemes in the list, you should write them with `://` part at the end. +In order to set up deeplinking support for Android platform, make sure to add all the schemes you would like your app to handle into the `Android URI Schemes` list. **Note:** Pay attention to tooltip which says that when you are entering URI schemes in the list, you should write them with `://` part at the end(append it with a host name is OK either, e.g. my_app://host). Unlike iOS counter part, Android post-build process will not perform any injection of custom Unity `Activity` class in order to intercept deeplinks which have opened your Android app. Instead, Adjust SDK internally relies on above mentioned [Application.deepLinkActivated](https://docs.unity3d.com/ScriptReference/Application-deepLinkActivated.html) method to get information about deeplink directly from Unity API. SDK will automatically perform everything which is needed to potentially reattribute your users via deeplinking. And, like already mentioned above - feel free to implement this same method in order to obtain deeplink which has opened your Android app.