Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Deeplink] Android URL Schemes Addition revise #267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions Assets/Adjust/Editor/AdjustEditorPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -141,48 +140,41 @@ 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);
AddAndroidNamespaceAttribute(manifest, "host", uri.Host, androidSchemeNode);
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;
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ What iOS post-build process will perform under the hood will be swizzling of som

### <a id="dl-app-android"></a>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.

Expand Down