我试图通过adb测试Android深层链接网址来启动我的应用程序

时间:2015-03-02 03:07:27

标签: android android-manifest adb deep-linking

当我在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>

11 个答案:

答案 0 :(得分:63)

您不需要指定活动的完整路径,但如果您想测试您是否对> 中的URI做出了正确反应,请指定应用包:

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

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

答案 1 :(得分:18)

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

TLDR:Android Studio - &gt;运行 - &gt;编辑配置

将启动选项中的启动更改为“URL”,并在文本字段URL中输入正确的URL:“something://”

答案 2 :(得分:9)

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

或者,您可以使用深层链接测试器应用程序直接在Android上测试深层链接,而不是使用adb:

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

无需提及任何包名称或组件名称。只需输入深层链接并开火即可。

我发现通过adb测试深层链接有时会变得比较困难。因此,我已经构建了这个小应用程序来实现它。

答案 3 :(得分:7)

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

enter image description here

  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

答案 4 :(得分:1)

这是命令

adb shell am start -d your-deep-link

示例

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

答案 5 :(得分:1)

命令

adb shell dumpsys package domain-preferred-apps

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

答案 6 :(得分:1)

通过运行 adb shell命令测试深层链接对我来说似乎很麻烦。因此,我尝试了一种轻松解决方案,以减少使用.bat文件多次测试深层链接的时间和精力。

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

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

,然后将扩展名.txt更改为.bat的文件。现在,您刚刚创建了bat文件来测试Deeplink。尝试仅使用一个字母来命名蝙蝠文件(就像我命名为d.bat一样,“ d”代表“深层链接”以便于理解),因为这样可以减少您的打字时间。

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

它会很漂亮!

答案 7 :(得分:1)

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

就用那个!

我有三个关于 App Links Assistant 的快速免责声明,他的回答中缺少这些声明,而且评论太长了。

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

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

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

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

答案 8 :(得分:0)

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

<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的测试设备外壳中的帮助文本更新。

答案 9 :(得分:0)

尝试一下:

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 

,此外,您还需要先安装该应用程序才能注册深层链接。

答案 10 :(得分:0)

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

  1. 通过选择编辑配置...选项打开运行/调试配置对话框,如下图所示: open 'Run/Debug Configurations' dialog

  2. 然后添加一个新配置,其中包含如下图所示的选项(如果您使用 Firebase 动态链接,则在 URL 字段中输入动态链接的短链接,否则在 URL 字段中输入深层链接) : Options in the 'Run/Debug Configurations' dialog

  3. 之后,您将找到运行配置,选择它,然后按运行enter image description here

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

相关问题