簡體   English   中英

我正在嘗試通過 adb 測試 android 深層鏈接 url 以啟動我的應用程序

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

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

我的問題是為什么我需要獲取活動的完整路徑而不僅僅是 package 名稱? 因為當外部應用程序或瀏覽器嘗試深度鏈接時,它們不會調用我的應用程序中的活動。

這是我的 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>

你並不需要指定到你的活動完整的路徑,但如果你想測試你是否你的應用程序作出適當的反應,以URI只指定的應用程序包:

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

您提供的命令中也存在錯誤 - 應該是example://gizmos而不是example:gizmos

這是命令

adb shell am start -d your-deep-link

例子

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

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://”

正如另一個答案所提到的,它應該是“example://gizmos”而不是“example:gizmos”

或者,您可以使用深層鏈接測試器應用程序直接在 android 上測試深層鏈接,而不是使用 adb:

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

無需提及任何包名稱或組件名稱。 只需輸入深層鏈接並啟動。

我發現通過 adb 測試深層鏈接有時很復雜而且很困難。 因此,我構建了這個小應用程序來做到這一點。

您可以從 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

嘗試這個:

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 

並且您還需要先安裝該應用程序才能注冊深層鏈接。

您的命令不正確,因為您正在嘗試使用不正確的包名稱,而不是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

命令

adb shell dumpsys package domain-preferred-apps

打印系統已知的所有活動深層鏈接處理程序也非常有幫助。 如果您的應用在此處丟失,則您的深層鏈接設置顯然有問題。

以防萬一其他人遇到我遇到的問題,即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 相同的錯誤消息。

根據我剛剛獲得的經驗,我建議使用可用 adb 命令列表。 它似乎比運行 Android 8 的測試設備的外殼中的幫助文本更新。

我發現的最好方法是通過 Android Studio 本身。

  1. 通過選擇Edit Configurations...選項打開Run/Debug Configurations對話框,如下圖所示: 打開“運行/調試配置”對話框

  2. 之后添加一個新配置,如下圖所示(如果您使用 Firebase 動態鏈接,則在 URL 字段中輸入動態鏈接的短鏈接,否則在 URL 字段中輸入深層鏈接): “運行/調試配置”對話框中的選項

  3. 之后,您將找到運行配置,選擇它,然后按Run 在此處輸入圖片說明

為要測試的每個鏈接添加盡可能多的運行配置。

在 Google Play 中搜索DeepLink 下載 apk(通過其他支持下載的站點)。 然后在模擬器上安裝應用程序。 例如, https://play.google.com/store/apps/details?id=com.waterbottle.testdeeplink

在此處輸入圖像描述

通過運行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.bat ,“d”代表“深層鏈接”以便於理解),因為它可以減少您的打字時間。

第 2 步:現在在 Android Studio 中打開您的terminal並轉到您的 bat 文件位置,然后輸入您的文件名(不帶擴展名)並按 Enter。 例如cd your/bat/file/location/d這里假設“d”是您的 bat 文件名。

它會工作得很好!

我發現 Savas Adar 的答案使用起來最友好,為此目的擁有一個內置工具也更有意義。

就用那個!

我有三個關於 App Links Assistant 的快速免責聲明,他的回答中缺少這些聲明,而且評論太長了。

  1. 打開應用鏈接助手。 我在工具菜單中找不到它。 所以雙擊 Shift 並輸入 App Link Assistant 從 Android Studio 運行它

  2. 按“運行測試”將清除編輯文本框,因此我發現每次我想重新嘗試測試時都必須復制並粘貼我的鏈接。 愚蠢的我自己沒有閱讀它上面的文字,說在運行測試后,會創建一個運行配置,並附有先前的 url。 (屏幕頂部,設備菜單左側)。 只需使用您想要的 url 選擇運行配置。

  3. 我發現按下“運行測試”會重新啟動應用程序,這與 ABD 方法不同,ABD 方法在我想調試之前沒什么大不了的(只是速度較慢)。 我在調試模式下運行應用程序,然后按下運行測試,這將停止我的調試會話並重新啟動應用程序...

解決方案是從第 2 點選擇運行配置,並將其作為調試運行。

如果您的深層鏈接具有 http 或 https 方案,您可以使用 Android 中的 google 文本框:

在此處輸入圖像描述

只需在那里復制您的深層鏈接

以下應該工作

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

這里

例子://小發明

是您設置的 URI 方案。

但是如果你想將額外的參數傳遞給 URI scheme 並測試它,

例子

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

那么命令就是

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM