【问题标题】:Android Deep link opens with "Launch URL" but not with typing exact urlAndroid Deep 链接以“启动 URL”打开,但不输入确切的 url
【发布时间】:2021-05-05 14:43:55
【问题描述】:

我一直在使用 Android 的隐式深层链接,并且直接在导航图中定义了深层链接。

问题是当我在下面的配置中使用“启动选项”时,我的深层链接会很好地打开片段,但是当我输入确切的 URL 时它就不起作用(顺便说一句,我尝试使用 http、https 输入,没有它,在笔记应用程序和浏览器中直接)。

你猜为什么会这样?

我的代码的某些部分相关: 导航图:

    <fragment
        android:id="@+id/usedPriceFragment"
        android:name="UsedPriceFragment"
        android:label="UsedPriceFragment">
        <argument
            android:name="clearCache"
            android:defaultValue="false"
            app:argType="boolean"
            app:nullable="false" />
        <deepLink
            android:id="@+id/deepLink"
            app:action="ACTION_VIEW"
            app:mimeType="type/subtype"
            app:uri="example.com/example/prices/used" />
    </fragment>

清单:

<activity
            android:name="activity.MainActivity"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustResize">

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <data android:pathPrefix="/example/prices" />
            </intent-filter>
            <nav-graph android:value="@navigation/navigation_graph_main" />

编辑: 详细版:系统询问我是否要使用我的应用程序打开 URL。我点击是,然后主页启动而不是我要打开的片段。

【问题讨论】:

    标签: android android-intent android-architecture-navigation android-deep-link


    【解决方案1】:

    通过在浏览器中键入深层链接来测试它们通常不是一个好主意。浏览器通常会尝试自己处理 URL,并且不会将其传递给操作系统。

    您应该改为通过 ADB 本身发送意图,如下所示:

    adb shell am start -a android.intent.action.VIEW \
        -c android.intent.category.BROWSABLE \
        -d "http://domain.name:optional_port"
    

    更多信息可通过in the documentation 获取应用链接。

    作为旁注,我假设您的代码中的 example.com 是占位符文本。如果不是,当您使用autoVerify="true" 时,它必须是您控制的域,并且具有set up verification for

    【讨论】:

    • 感谢您抽出时间来写答案。是的,example.com 只是一个占位符;但即使使用您编写的命令,我的片段也没有被打开,LogCat 中也没有日志。我准确地输入了https://example.com/example/prices/used,但仍然没有运气。
    • 其实是系统问我要不要用我的app打开url。我单击是,然后主页启动而不是我要打开的片段。
    • 这更有希望,至少它在您的应用程序中!不确定我能否提供更多帮助,抱歉,mimeType 可能需要检查?
    • 我尝试删除它,但也没有用。
    • 如果您删除已添加的intent-filter 并依赖自动生成的会怎样?
    【解决方案2】:

    singleTask 模式下打开活动时,您需要手动处理接收到的意图。所以添加这行代码解决了这个问题。

    if (mainActivity.tabManager.findActiveNavController()?.handleDeepLink(intent) == true) {
                return
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-17
      • 2015-06-12
      • 2011-10-23
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 2017-11-12
      相关资源
      最近更新 更多