赞
踩
原本查了很多资料,准备再AndroidStudio中去处理的,结果发现Unity3D2020以后支持启用深层链接。
这样我们要做的工作就少很多了,只需要用好函数即可。
这是官网提供的例子:
U3D端:
- using UnityEngine;
- using UnityEngine.SceneManagement;
-
- public class ProcessDeepLinkMngr : MonoBehaviour
- {
- public static ProcessDeepLinkMngr Instance { get; private set; }
- public string deeplinkURL;
- private void Awake()
- {
- if (Instance == null)
- {
- Instance = this;
- Application.deepLinkActivated += onDeepLinkActivated;
- if (!string.IsNullOrEmpty(Application.absoluteURL))
- {
- // Cold start and Application.absoluteURL not null so process Deep Link.
- onDeepLinkActivated(Application.absoluteURL);
- }
- // Initialize DeepLink Manager global variable.
- else deeplinkURL = "[none]";
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- }
-
- private void onDeepLinkActivated(string url)
- {
- // Update DeepLink Manager global variable, so URL can be accessed from anywhere.
- deeplinkURL = url;
-
- // Decode the URL to determine action.
- // In this example, the app expects a link formatted like this:
- // unitydl://mylink?scene1
- string sceneName = url.Split("?"[0])[1];
- bool validScene;
- switch (sceneName)
- {
- case "scene1":
- validScene = true;
- break;
- case "scene2":
- validScene = true;
- break;
- default:
- validScene = false;
- break;
- }
- if (validScene) SceneManager.LoadScene(sceneName);
- }
- }
Android XML配置:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
- <application>
- <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.BROWSABLE" />
- <data android:scheme="unitydl" android:host="mylink" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
这里unitydl可以换成项目名,mylink可以换成包名(参考淘宝之类的第三方跳转)。
- <html>
- <head>
- <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
- </head>
- <body >
- <h1>My Deep Link Test page</h1>
- <p><a href="unitydl://mylink">Launch</a></p>
- <p><a href="unitydl://mylink?parameter">Launch with Parameter</a></p>
- </body>
- </html>
问号是拉起app时候传的信息。html可以用txt文本编辑测试~IOS还没测试,不过基本一样。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。