Skip to content

Commit 3856917

Browse files
authored
Update README.md
1 parent 1919716 commit 3856917

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,49 @@ public void onDeeplink(string deeplink) {
1515
2. Copy the entire UnityDeeplinks folder into your Unity project Assets folder
1616

1717
## Android
18+
There are two alternatives to handle a deeplink by a Unity app, depending on how your Unity project is currently built. It's up to you to decide which way to go.
1819

19-
### If you have not yet overridden the default UnityPlayerActivity
20-
You will have to use the provided UnityPlayerActivity subclass as follows:
20+
### Alternative 1: Subclassing UnityPlayerActivity
21+
In this approach, you use a subclass of the default *UnityPlayerActivity*, which contains deeplink-handling code that marshals deeplinks into your Unity script. This is more recommended approach, as it is the least complex. If you have no previous plans to subsclass UnityPlayerActivity, it's a good approach because then the subclassed code would not conflict with anything. If you do have plans to subclass UnityPlayerActivity, however, it would usually also be a good approach as the code changes you need to make are minimal. You will have to use the provided *MyUnityPlayerActivity* subclass as follows:
2122

2223
* Replace the default UnityPlayerActivity in your Assets/Plugins/Android/AndroidManifest.xml with com.trophit.MyUnityPlayerActivity:
2324

2425
```
2526
<!--
26-
<activity android:name="com.unity3d.player.UnityPlayerActivity">
27+
<activity android:name="com.unity3d.player.UnityPlayerActivity" ...
2728
-->
28-
<activity android:name="com.trophit.MyUnityPlayerActivity">
29+
<activity android:name="com.trophit.MyUnityPlayerActivity" ...
30+
```
31+
32+
* Add the following inside the <activity> tag, assuming your deeplink URL scheme is myapp://
33+
```
34+
<intent-filter>
35+
<action android:name="android.intent.action.VIEW" />
36+
<category android:name="android.intent.category.DEFAULT" />
37+
<category android:name="android.intent.category.BROWSABLE" />
38+
<data android:scheme="myapp" />
39+
</intent-filter>
2940
```
3041

3142
* Optional: by default, *MyUnityPlayerActivity* calls a Unity script method `onDeeplink` on a game object called *UnityDeeplinks*. If you wish to change the name of the object or method, you should edit *Assets/UnityDeeplinks/Android/MyUnityPlayerActivity.java*, change the values of the `gameObject` and/or `deeplinkMethod` static properties and rebuild the *UnityDeeplinks.jar* file as instructed below
3243

44+
### Alternative 2: Adding a Deeplink Activity
45+
In this approach, a second activity with deeplink-handling code is added to the Unity project, without subclassing the default activity. Use this is case where option #1 is not acceptable (code is too complex, not under your control, cannot be subclassed, etc)
46+
47+
* Add the following activity to your Assets/Plugins/Android/AndroidManifest.xml, assuming your deeplink URL scheme is myapp://
48+
```
49+
<activity android:name="com.trophit.DeeplinkActivity" android:exported="true">
50+
<intent-filter>
51+
<action android:name="android.intent.action.VIEW" />
52+
<category android:name="android.intent.category.DEFAULT" />
53+
<category android:name="android.intent.category.BROWSABLE" />
54+
<data android:scheme="myapp" />
55+
</intent-filter>
56+
</activity>
57+
```
58+
59+
* Optional: by default, *DeeplinkActivity* calls a Unity script method `onDeeplink` on a game object called *UnityDeeplinks*. If you wish to change the name of the object or method, you should edit *Assets/UnityDeeplinks/Android/DeeplinkActivity.java*, change the values of the `gameObject` and/or `deeplinkMethod` static properties and rebuild the *UnityDeeplinks.jar* file as instructed below
60+
3361
### Building the UnityDeeplinks.jar file
3462
Only perform this step if you made changes to *Assets/UnityDeeplinks/Android/MyUnityPlayerActivity.java* or would like to rebuild it using an updated version of Unity classes, Android SDK, JDK and so on.
3563

@@ -59,3 +87,17 @@ adding: com/trophit/MyUnityPlayerActivity.class(in = 1504) (out= 789)(deflated 4
5987
This creates/updates a *UnityDeeplinks.jar* file under your Unity project's Assets/UnityDeeplinks folder
6088

6189
* Continue to build and test your Unity project as usual in order for any jar changes to take effect
90+
91+
## iOS
92+
93+
## Testing
94+
95+
* Prepare a dummy html page that is accessible by your mobile device:
96+
```
97+
<body>
98+
<a href="myapp://?a=b">deeplink test</a>
99+
</body>
100+
```
101+
102+
* Open the web page on the device browser and click the deeplink
103+
* The Unity app should open and the onDeeplink Unity script method should be invoked, performing whatever it is you designed it to perform

0 commit comments

Comments
 (0)