【问题标题】:I am trying to test android deep link urls through adb to launch my app我正在尝试通过 adb 测试 android 深层链接 url 以启动我的应用程序
【发布时间】:2015-05-02 08:26:34
【问题描述】:

当我在 adb 中输入命令时:

./adb shell am start -W -a android.intent.action.VIEW -d "example:gizmos" com.myapp

我收到此错误:

Starting: Intent { act=android.intent.action.VIEW dat=example://gizmos pkg=com.myapp }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp }

但是当我在 adb 中输入命令时:

./adb shell am start -W -a android.intent.action.VIEW -d "example:gizmos" com.myapp.activity.DeepLinkActivity

一切正常,我收到消息,我可以在手机上看到活动启动:

Starting: Intent { act=android.intent.action.VIEW dat=example://gizmos cmp=com.myapp.activity.DeepLinkActivity }
Status: timeout
Activity: com.myapp.activity.DrawerActivity
Complete

我的问题是为什么我需要获取活动的完整路径而不仅仅是包名称?因为当外部应用程序或浏览器尝试深度链接时,它们不会调用我的应用程序中的活动。

这是我的 AndroidManifest.xml

<activity
        android:name=".activity.DeepLinkActivity">
        <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="example"
                  android:host="gizmos" />

        </intent-filter>
</activity>

【问题讨论】:

    标签: android android-manifest adb deep-linking


    【解决方案1】:

    您无需指定 Activity 的完整路径,但如果您想测试您是否对 URI in 做出正确反应,只需指定应用程序包:

    adb shell am start -a android.intent.action.VIEW -d "example://gizmos" com.myapp
    

    您提供的命令也存在错误 - 应该是 example://gizmos 而不是 example:gizmos

    【讨论】:

      【解决方案2】:

      正如提到的另一个答案,它应该是“example://gizmos”而不是“example:gizmos”

      或者,您可以使用深度链接测试器应用直接在 android 上测试深度链接,而不是使用 adb:

      https://play.google.com/store/apps/details?id=com.manoj.dlt

      无需提及任何包名或组件名。只需输入深层链接并触发。

      我发现通过 adb 测试深层链接有时很麻烦而且很困难。因此,我构建了这个小应用程序来做到这一点。

      【讨论】:

        【解决方案3】:

        您的命令不正确,因为您尝试使用不正确的包名称,而不是com.myapp.activity.DeepLinkActivity,您必须只编写'application Id'在build gradle(Module:app)中指定的包名称,例如如果您的applicationId 是@ 987654322@,那么你的命令是这样的:

        adb shell am start -W -a android.intent.action.VIEW -d  "example://gizmos" com.companyname
        

        【讨论】:

          【解决方案4】:

          这里解释了android studio的最佳解决方案:https://code.tutsplus.com/tutorials/how-to-enable-deep-links-on-android--cms-26317

          TLDR : Android Studio --> 运行 --> 编辑配置

          将 Launch Options 中的 Launch 更改为“URL”,并在文本字段 URL 中输入正确的 url:“something://”

          【讨论】:

            【解决方案5】:

            以防其他人遇到我遇到的问题,即 adb shell am start ... 不起作用,如果您的意图过滤器中有 file:///...content://...URI 并指定了 MIME 类型,例如

            <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="content" />
              <data android:scheme="file" />
              <data android:mimeType="text/plain" />
              <data android:host="*" />
            </intent-filter>
            

            需要在命令行中使用-t参数指定mime类型:

            adb shell am start -W -a android.intent.action.VIEW -d "file:///sdcard/myfolder/myfile.txt" -t "text/plain" com.myapp
            

            否则您会收到与 OP 相同的错误消息。

            根据我刚刚获得的经验,我建议使用this 可用 adb 命令列表。它似乎比我运行 Android 8 的测试设备外壳中的帮助文本更新。

            【讨论】:

              【解决方案6】:

              这是命令

              adb shell am start -d your-deep-link
              

              例子

              adb shell am start -d rm://yoursettingpage/v1
              

              【讨论】:

              • 这是这个问题的最佳和简单的答案。
              • 完全同意:迄今为止的最佳答案
              • 如果您的深层链接中有额外内容(例如“?a=100&b=200”),用"s 包围深层链接,用's 包围 adb-shell。例如:adb shell 'am start -d "example://deeplink?a=100&amp;b=200"'
              【解决方案7】:

              试试这个:

              adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d 'yourdeeplink'
              
              -a android.intent.action.VIEW -> action  -c android.intent.category.BROWSABLE -> category -d 'deeplink' -> data 
              

              您还需要先安装应用才能注册深层链接。

              【讨论】:

              • -a android.intent.action.VIEW -> 动作 ---------- -c android.intent.category.BROWSABLE -> 类别-------- -- -d 'deeplink' -> data ---------- 而且您需要先安装应用才能注册深度链接。
              【解决方案8】:

              命令

              adb shell dumpsys package domain-preferred-apps
              

              对于打印系统已知的所有活动深度链接处理程序也非常有帮助。如果此处缺少您的应用,则您的深层链接设置显然有问题。

              【讨论】:

                【解决方案9】:

                通过运行 adb shell 命令 测试 深度链接 对我来说似乎很麻烦。所以我尝试了一个简单的解决方案来减少我使用.bat文件多次测试深度链接的任务和时间。

                第 1 步:首先创建一个 .txt 文件并在此处粘贴您的 ADB 命令 -

                adb shell am start -W -an android.intent.action.VIEW -d <Your URL> <Your Package>
                

                并将扩展名为.txt 的文件保存为.bat。现在您刚刚创建了 bat 文件来测试深度链接。尝试只使用一个字母来命名 bat 文件(就像我命名为 d.bat 一样,“d”代表“深度链接”以便于理解),因为它可以减少您输入的时间。

                第 2 步:现在在 Android Studio 中打开您的 terminal 并转到您的 bat 文件位置,只需输入您的文件名(不带扩展名)并按 Enter。例如cd your/bat/file/location/d 这里假设“d”是你的 bat 文件名。

                它会很好用!

                【讨论】:

                • 缺少“-c android.intent.category.BROWSABLE”
                【解决方案10】:

                您可以从 Android Studio 界面测试您的深层链接。

                1. 选择工具 > 应用链接助手。
                2. 点击应用链接助手中的测试应用链接。
                3. 在 URL 字段中输入您要测试的 URL,例如,http://recipe-app.com/recipe/grilled-potato-salad
                4. 点击运行测试。

                了解如何通过 Android Studio 界面实现应用链接。 https://developer.android.com/studio/write/app-link-indexing#testindent

                【讨论】:

                • 这似乎只适用于带有 http 或 https 方案的应用链接
                【解决方案11】:

                我发现 Savas Adar 的答案使用起来最友好,为此使用内置工具也更有意义。

                就用那个吧!

                我有三个关于应用链接助手的快速免责声明,他的回答中缺少这些声明,并且评论太长。

                1. 打开应用链接助手。 我在“工具”菜单中找不到它。 所以双击 Shift 并输入 App Link Assistant 以从 Android Studio 运行它

                2. 按“运行测试”会清除编辑文本框,因此我发现每次我想重新尝试测试时都必须复制并粘贴我的链接。愚蠢的我自己没有阅读上面的文字,说在运行测试后会创建一个运行配置,并附加上一个 url。 (屏幕顶部,设备菜单左侧)。只需使用您想要的 url 选择运行配置即可。

                3. 我发现按下“运行测试”会重新启动应用程序,这与 ABD 方法不同,后者在我想调试之前没什么大不了(只是更慢)。 我在调试模式下运行应用程序,然后按下运行测试,这将停止我的调试会话并重新启动应用程序...

                解决方案是从第 2 点中选择运行配置,然后将其作为调试运行。

                【讨论】:

                  【解决方案12】:

                  我发现最好的方法是通过 Android Studio 本身。

                  1. 通过选择 Edit Configurations... 选项打开 Run/Debug Configurations 对话框,如下图所示:

                  2. 然后添加一个带有下图所示选项的新配置(如果您使用的是 Firebase 动态链接,则在 URL 字段中输入动态链接的短链接,否则在 URL 字段中输入您的深层链接):

                  3. 之后,您会找到运行配置,选择它,然后按运行

                  为您要测试的每个链接添加尽可能多的运行配置。

                  【讨论】:

                  • 这应该是当前的答案,因为屏幕截图显示了要做什么。
                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2019-01-29
                  • 2015-07-31
                  • 2020-01-05
                  • 2022-07-14
                  • 1970-01-01
                  • 2014-11-01
                  • 2017-05-29
                  相关资源
                  最近更新 更多