我想在设备上创建指向应用程序的链接,但无法正常工作

时间:2019-06-09 23:33:09

标签: android deep-linking

我想在设备上创建到应用程序的链接(该应用程序不是我的,因此我无法对其进行编辑)。 我发现它具有一个如下所示的意图过滤器。

<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>

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

2 个答案:

答案 0 :(得分:0)

您必须在单击

后必须重定向到的特定活动上添加意图过滤器
 <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

答案 1 :(得分:0)

深入链接到应用程序并非易事,因为不同的浏览器,应用程序内浏览器和设备的行为方式不同。

一些背景: 您上面提到的应用声明了用于深层链接的“ URI方案”,并为深层链接设置了https:\\方案。这已经是一个问题,因为该方案已被浏览器应用程序广泛使用(这意味着,如果您为该方案设置了默认应用程序,则除非将其重置,否则将无法打开该应用程序)。

此外,某些浏览器不支持重定向到https://ravkavonline.co.il的操作。例如。在Chrome中,您无法使用URI Scheme启动应用程序(并且需要使用Intent)。这意味着您需要具有一些逻辑,这些逻辑将检测浏览器的用户代理,并尝试根据正确的策略进行深层链接。

此外,如果未安装该应用程序,则UR​​I方案重定向将失败,并将用户留在空白页上。因此,您还需要处理这种情况。

例如:

window.location.href = "yourapp://";
setTimeout(function () {
    window.location.href = ...store_link_for_your_app..;
}, 1000);