首页 > 解决方案 > 我想在我的设备上创建一个应用程序的链接,但它不工作

问题描述

我想在我的设备上创建一个应用程序的链接(该应用程序不是我的,所以我无法编辑它)。我发现它有一个看起来像这样的意图过滤器。

<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="ravkavonline.co.il" 
          android:pathPrefix="/pos/" android:scheme="https"/>
 </intent-filter>

我写了以下链接

 <a href="https://ravkavonline.co.il">click me!</a>

但它在浏览器中将我发送到他们的网站,而不是打开应用程序。

标签: androiddeep-linking

解决方案


您必须在单击后必须重定向的特定活动上添加意图过滤器

 <activity
        android:name=".ui.SplashActivity"
        android:screenOrientation="portrait"
        android:exported="true">
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="http"
                android:host="www.xyz.com"
                android:pathPrefix="/"/>
        </intent-filter>

您必须在活动类中添加此行

 Intent appLinkIntent = getIntent();
    String appLinkAction = appLinkIntent.getAction();
    Uri appLinkData = appLinkIntent.getData();

上面的代码非常适合我。此外,您还必须按照以下链接逐步进行深度链接 Android Studio

https://developer.android.com/studio/write/app-link-indexing.html

https://developer.android.com/training/app-links/deep-linking


推荐阅读