简体   繁体   English

我正在尝试通过 adb 测试 android 深层链接 url 以启动我的应用程序

[英]I am trying to test android deep link urls through adb to launch my app

When I type the command in adb:当我在 adb 中键入命令时:

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

I get this error:我收到此错误:

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 }

But when I type the command in adb:但是当我在 adb 中键入命令时:

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

Everything works fine and I get the message and I can see the activity launch on the phone:一切正常,我收到消息,我可以在手机上看到活动启动:

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

My question is why do I need to get full path of my activity and not just package name?我的问题是为什么我需要获取活动的完整路径而不仅仅是 package 名称? Because when the external apps or browser will try to deep link they will not invoke the activity in my app.因为当外部应用程序或浏览器尝试深度链接时,它们不会调用我的应用程序中的活动。

This is my AndroidManifest.xml这是我的 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>

You don't need to specify full path to your activity, but if you want to test whether you react properly to URI in your app just specify app package:你并不需要指定到你的活动完整的路径,但如果你想测试你是否你的应用程序作出适当的反应,以URI只指定的应用程序包:

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

Also there is bug in command you provided - there should be example://gizmos not example:gizmos您提供的命令中也存在错误 - 应该是example://gizmos而不是example:gizmos

Here is the command这是命令

adb shell am start -d your-deep-link

Example例子

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

The best solution for android studio is explained here: https://code.tutsplus.com/tutorials/how-to-enable-deep-links-on-android--cms-26317 android studio 的最佳解决方案在这里解释: https : //code.tutsplus.com/tutorials/how-to-enable-deep-links-on-android--cms-26317

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

Change Launch in Launch Options to "URL" and enter in the text field URL the correct url: "something://"将 Launch Options 中的 Launch 更改为“URL”并在文本字段 URL 中输入正确的 URL:“something://”

As the other answer mentioned, it should be "example://gizmos" and not "example:gizmos"正如另一个答案所提到的,它应该是“example://gizmos”而不是“example:gizmos”

Alternatively, instead of using adb, you can test deep links directly on android using deep link tester app:或者,您可以使用深层链接测试器应用程序直接在 android 上测试深层链接,而不是使用 adb:

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

No need to mention any package name or component name.无需提及任何包名称或组件名称。 Just type the deep link and fire.只需输入深层链接并启动。

I've found testing deep links through adb to be cubersome and difficult at times.我发现通过 adb 测试深层链接有时很复杂而且很困难。 Hence, I've built this small app to do it.因此,我构建了这个小应用程序来做到这一点。

You can test your deeplink from Android Studio interface.您可以从 Android Studio 界面测试您的深层链接。

在此处输入图片说明

  1. Select Tools > App Links Assistant.选择工具 > 应用链接助手。
  2. Click Test App Links in the App Links Assistant.单击应用程序链接助手中的测试应用程序链接。
  3. Enter the URL you want to test in the URL field, for example, http://recipe-app.com/recipe/grilled-potato-salad .在 URL 字段中输入要测试的 URL,例如http://recipe-app.com/recipe/grilled-potato-salad
  4. Click Run Test.单击运行测试。

Take a look for learn how to implement applinks via Android Studio Interface.查看了解如何通过 Android Studio 界面实现应用链接。 https://developer.android.com/studio/write/app-link-indexing#testindent https://developer.android.com/studio/write/app-link-indexing#testindent

Try this:尝试这个:

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 

and also you need to install the app first in order to register the deeplink.并且您还需要先安装该应用程序才能注册深层链接。

您的命令不正确,因为您正在尝试使用不正确的包名称,而不是com.myapp.activity.DeepLinkActivity您必须仅写入 build gradle(Module: app) 中通过“application Id”指定的包名称,例如,如果您的 applicationId 是com.companyname ,那么您的命令将是这样的:

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

The command命令

adb shell dumpsys package domain-preferred-apps

is also very helpful to print all active deep link handlers known to the system.打印系统已知的所有活动深层链接处理程序也非常有帮助。 If your app is missing here, there's obviously something wrong with your deep link setup.如果您的应用在此处丢失,则您的深层链接设置显然有问题。

Just in case someone else has the problem that I had, namely that adb shell am start ... does not work, if you have a file:///... or content://... URI in your intent filter that has a mime type specified, for example以防万一其他人遇到我遇到的问题,即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>

You need to specify the mime type on the command line by using the -t parameter:您需要使用 -t 参数在命令行上指定 mime 类型:

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

or else you get the same error message as the OP.否则您会收到与 OP 相同的错误消息。

Based on the experience I just had I recommend using this list of available adb commands.根据我刚刚获得的经验,我建议使用可用 adb 命令列表。 It seems to be more recent than the help texts from the shell of my test device running Android 8.它似乎比运行 Android 8 的测试设备的外壳中的帮助文本更新。

The best way I found is through Android Studio itself.我发现的最好方法是通过 Android Studio 本身。

  1. Open the Run/Debug Configurations dialog by selecting Edit Configurations... option like in the image below:通过选择Edit Configurations...选项打开Run/Debug Configurations对话框,如下图所示: 打开“运行/调试配置”对话框

  2. After that add a new configuration with options like in the below image (if you're using Firebase Dynamic Links then enter your dynamic link's short link in the URL field else enter your deep link instead in the URL field):之后添加一个新配置,如下图所示(如果您使用 Firebase 动态链接,则在 URL 字段中输入动态链接的短链接,否则在 URL 字段中输入深层链接): “运行/调试配置”对话框中的选项

  3. After that, you'll find the run configuration, select it, and just press Run :之后,您将找到运行配置,选择它,然后按Run 在此处输入图片说明

Add as many run configurations for each link you want to test.为要测试的每个链接添加尽可能多的运行配置。

Search Google Play for DeepLink .在 Google Play 中搜索DeepLink Download apk (via other sites that support downloading).下载 apk(通过其他支持下载的站点)。 Then install the application on emulator.然后在模拟器上安装应用程序。 For instance, https://play.google.com/store/apps/details?id=com.waterbottle.testdeeplink .例如, https://play.google.com/store/apps/details?id=com.waterbottle.testdeeplink

在此处输入图像描述

Testing deep-linking by running adb shell command seems troublesome to me.通过运行adb shell 命令测试深层链接对我来说似乎很麻烦。 So I tried an Easy Solution to reduce my task and time to test deep-linking multiple time using .bat file.所以我尝试了一个简单的解决方案来减少我使用.bat文件多次测试深层链接的任务和时间。

Step 1 : First create a .txt file and paste here your ADB command -第 1 步:首先创建一个.txt文件并在此处粘贴您的 ADB 命令 -

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

and save the file changing .txt extension into .bat .并将更改.txt扩展名的文件保存为.bat Now you have just created your bat file to test deeplink.现在您刚刚创建了 bat 文件来测试深层链接。 Try to use just one letter to name the bat file (Like I named d.bat , "d" for "deeplinking" for easy understanding) because it reduce your time of typing.尝试仅使用一个字母来命名 bat 文件(就像我将d.bat命名为d.bat ,“d”代表“深层链接”以便于理解),因为它可以减少您的打字时间。

Step 2: Now open your terminal in Android studio and go to your bat file location and just type your file name ( without extension ) and press enter.第 2 步:现在在 Android Studio 中打开您的terminal并转到您的 bat 文件位置,然后输入您的文件名(不带扩展名)并按 Enter。 For example cd your/bat/file/location/d here suppose "d" is your bat file name.例如cd your/bat/file/location/d这里假设“d”是您的 bat 文件名。

It will work spiffy!它会工作得很好!

I found Savas Adar's answer the most friendly to use, also makes much more sense to have an inbuilt tool for that purpose.我发现 Savas Adar 的答案使用起来最友好,为此目的拥有一个内置工具也更有意义。

Just use that!就用那个!

I have three quick disclaimers about the App Links Assistant which are missing in his answer and a comment was too long.我有三个关于 App Links Assistant 的快速免责声明,他的回答中缺少这些声明,而且评论太长了。

  1. Open App Links Assistant.打开应用链接助手。 I couldn't find it in the Tools menu.我在工具菜单中找不到它。 So double press Shift and type App Link Assistant to run it from Android Studio所以双击 Shift 并输入 App Link Assistant 从 Android Studio 运行它

  2. Pressing "Run Test" would clear the edit text box so I found myself having to copy and paste my link every time I wanted to re-try the test.按“运行测试”将清除编辑文本框,因此我发现每次我想重新尝试测试时都必须复制并粘贴我的链接。 Foolish of myself not reading the text literally above it saying that after running a test a Run Configuration gets created with the previous url attached to it.愚蠢的我自己没有阅读它上面的文字,说在运行测试后,会创建一个运行配置,并附有先前的 url。 (Top of the screen, left of the device menu). (屏幕顶部,设备菜单左侧)。 Just select the run configuration with the url you want.只需使用您想要的 url 选择运行配置。

  3. I found that pressing "Run Test" would restart the app unlike the ABD approach which is no biggie (just slower) until I wanted to debug.我发现按下“运行测试”会重新启动应用程序,这与 ABD 方法不同,ABD 方法在我想调试之前没什么大不了的(只是速度较慢)。 I ran the app in the debug mode and then pressed Run Test which would stop my debugging sessions and restart the app...我在调试模式下运行应用程序,然后按下运行测试,这将停止我的调试会话并重新启动应用程序...

Solution is to choose the Run Configuration from point 2, and just run it as a debug.解决方案是从第 2 点选择运行配置,并将其作为调试运行。

If your deeplink has http or https scheme you can use the google text box in Android:如果您的深层链接具有 http 或 https 方案,您可以使用 Android 中的 google 文本框:

在此处输入图像描述

Just copy your deeplink there只需在那里复制您的深层链接

Following should work以下应该工作

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

Here这里

example://gizmos例子://小发明

is the URI scheme that you have setup.是您设置的 URI 方案。

But if you want to pass additional parameters to URI scheme and test it,但是如果你想将额外的参数传递给 URI scheme 并测试它,

example例子

example://gizmos?parameter1=23&parameter2=test例如://gizmos?parameter1=23&parameter2=test

then the command would be,那么命令就是

adb shell 'am start -W -a android.intent.action.VIEW -d "example://gizmos?parameter1=23&parameter2=test"' com.myapp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过亚行为我的应用启动“应用信息”屏幕? - How can I launch the App Info screen for my app through ADB? Android:通过adb shell am启动应用信息对话框 - Android: launch app info dialog via adb shell am 如何通过Facebook广告预览(或通过实时Facebook广告)在Android App中测试Facebook Deep Link - How to test Facebook Deep Link in Android App through facebook Ad preview (or) through realtime facebook ads 我正在尝试通过我的 android 应用程序将我的数据上传到 sql server - i am trying to upload my data on sql server through my android app 我正在尝试使用 adb monkey 命令通过 adb 启动设置,但它一直打印出“Killed”。 我怎样才能找出造成这种情况的原因? - I am trying to launch Settings through adb using the adb monkey command, but it keeps printing out "Killed". How can I find out what is causing this? 如何链接URL以启动我的Android应用程序? - How can I link a URL to launch my Android app? 如何为Deep Link Android App附加调试器触发调试启动? - How to attach debugger for Deep Link Android App trigger debug launch? 我正在尝试启动应用,并且崩溃了 - I am trying to launch app and it is crashing 尝试添加深度链接我的 Android 应用程序 - Trying to add Deep Linking my Android App Android应用程式中的深层连结 - Deep link in android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM