有太多深层链接(通用链接或应用链接)教程.但其中大多数都展示了如何在Android或IOS应用中启用它.此外还有付费云解决方案,但它们提供了许多功能.但是我在现实生活中面临三个主要问题:
我写了这个Q&A,这是我学习的结果(花了太多时间),以便有一个独特的,适用于所有案例的解决方案.
代码来自我的工作解决方案,但我删除了一些部分只是为了表明这个想法.如果存在一些编译问题,请按照算法编写自己的代码
这是解决方案,即使你知道一些步骤也要一步一步,因为代码中有技巧.还有一些解释在代码部分的注释行中,请阅读它们.
示例是使用最终的参数处理Android和IOS应用程序的深层链接http://example.com/v/,例如http://example.com/v/id-of-user?key=value.
1.配置Android
1.1将活动信息添加到AndroidManifest.xml文件中:
<activity
android:name=".appLinkHandlerActivity">
<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:host="example.com"
android:pathPrefix="/v/"
android:scheme="http" />
</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" />
<!—this intent is needed to handle links to myapp://share, I will explain later why we need it -->
<data
android:host="share"
android:scheme="myapp" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
1.2创建名为appLinkHandlerActivity的活动,该活动将处理单击的链接
public class appLinkHandlerActivity extends AppCompatActivity {
/* assume that user is clicked http://example.com/v/my-user-id
actCode will be …Run Code Online (Sandbox Code Playgroud)