怎样通过 ADB 测试 Android deeplink/深度链接?怎样通过 ADB 发送 deeplink 来启动应用程序?

Android 应用开发中,有时需要对应用是否能对 deeplink 做出正确处理进行测试,这时通过 ADB 模拟 deeplink 的打开是最方便的。

介绍

可以通过 ADB 的 am start 命令打开一个 deeplink/深度链接,无需指定处理它的 Activity,除了可以指定 deeplink 外,可以指定 action,包名 等信息。

adb shell am start -a android.intent.action.VIEW -d "https://itmob.cn/page/about" cn.itmob.demo

Starting: Intent { act=android.intent.action.VIEW dat=https://itmob.cn/... pkg=cn.itmob.deo }
Warning: Activity not started, its current task has been brought to the front

上面的命令即指定了 action 参数,也指定了用于打开 deeplink 的包名,此时这个 deeplink 会直接交由指定包名的应用处理,即使没有在应用设置的 “默认打开” 中添加要处理的 deeplink 链接,也会由该应用处理。

Deeplink settings

其他

也可以不指定包名,这时模拟的与真实应用场景更接近,系统会根据已知的过滤条件查找合适的应用来处理该 deeplink。

比如:

未指定包名,但指定了 action,将调用浏览器或支持处理它的应用来打开

adb shell am start -a android.intent.action.VIEW -d "https://itmob.cn/page/about"

Starting: Intent { act=android.intent.action.VIEW dat=https://itmob.cn/... }

Deeplink handled by browser

未指定包名,也未指定 action,支持处理它的应用可能有多个,会弹出选择应用的弹窗

adb shell am start -d "https://itmob.cn/page/about"

Starting: Intent { dat=https://itmob.cn/... }

Deeplink app selector

# Android  ADB  Deeplink 

作者:ITmob
来源:ITmob.cn
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×