簡體   English   中英

如何在 android 12 及更高版本上驗證 android 應用程序鏈接?

[英]How to verify android app links on android 12 and higher?

問題是通過 android 12 或更高版本中的鏈接打開應用程序。

在較低版本的 android 上一切正常。

當我查看“應用信息”->“默認打開”屏幕時。 我看到未經批准的鏈接。

當我在支持的 web 地址中打開該鏈接時,通過鏈接打開應用程序有效。

在此處輸入圖像描述

我已經閱讀了有關在 android 文檔中驗證意圖過濾器的內容,對我來說一切都很好。

https://developer.android.com/training/app-links/verify-site-associations#add-intent-filters

Have aded.well-known/assetlinks.json to my domain https://my.domain.net/.well-known/assetlinks.json content of.well-known/assetlinks.json (generated and checked with https:// developer.google.com/digital-asset-links/tools/generator

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "my.package.name",
               "sha256_cert_fingerprints": ["SHA_256"] }
}]

三重檢查我使用的是正確的 SHA_256。

還測試了如果.json 可以使用“語句列表生成器和測試器”,上面提到的鏈接。

AndroidManifest.xml 內的意圖過濾器

<intent-filter
   android:autoVerify="true"
   android:label="@string/login_to_app">
  
   <action android:name="android.intent.action.VIEW" />

   <category android:name="android.intent.category.DEFAULT" />
   <category android:name="android.intent.category.BROWSABLE" />

   <data
      android:host="my.domain.net"
      android:pathPrefix="/${dynamicVar}/our/application/"
      android:scheme="https" />
 </intent-filter>

此外,我將應用程序上傳到游戲商店只是為了確保這與 SHA 證書或游戲商店相關沒有問題,但沒有區別。

我還檢查了我的應用程序 package 名稱,它對於內部測試和調試都是正確的。

為了確保,我還添加了應用程序 package 名稱的每個組合。

很快:由於 web 地址不受支持,無法通過 android 12 及更高版本上的鏈接打開應用程序。

我知道需要使用.well-known/assetlinks.json 驗證鏈接當我手動檢查支持的 web 地址時,它可以正常工作,但這不是最終解決方案。

我無法弄清楚我在這里錯過了什么。

任何人都知道我在這里做錯了什么?

發生了什么變化?

從 Android 12 開始,他們引入了一種檢查受支持的 web 域的新方法。

android 的低版本保持不變。


android 12 中的驗證如何工作?

在安裝應用程序時,android 向意圖鏈接內的域發送異步請求,以檢查.well-known/assetlinks.json 是否存在且有效。


如何生成assetlinks.json?

我建議使用谷歌提供的這個工具來生成該文件。 它還可以檢查assetlinks.json 是否存在並正確設置。
發電機: https://developers.google.com/digital-asset-links/tools/generator

從哪里獲得 SHA-256 表格?

  1. 打開Android工作室
  2. 打開你的項目
  3. 單擊 Gradle(從右側面板,您將看到 Gradle 條)
  4. 點擊 Refresh(從 Gradle 欄點擊 Refresh,您將看到 List
  5. 您項目的 Gradle 腳本)
  6. 單擊您的項目(您的項目名稱表單列表(根))
  7. 點擊任務
  8. 點擊 Android
  9. 雙擊簽名報告(您將在運行欄中獲得 SHA1 和 MD5(有時會在 Gradle 控制台中))
  10. Select 應用程序模塊從模塊選擇下拉列表運行或調試您的應用程序

生成.json 文件后,將其放入域的根目錄(.well-known/assetlinks.json)。
我建議手動打開它以確保。
https://my.domain.com/.well-known/assetlinks.json

在應用程序中設置 Intent 鏈接
給你 AndroidManifest.xml 添加

<!-- Make sure you explicitly set android:autoVerify to "true". -->
  <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <!-- If a user clicks on a shared link that uses the "http" scheme, your
         app should be able to delegate that traffic to "https". -->
    <data android:scheme="http" />
    <data android:scheme="https" />

    <!-- Include one or more domains that should be verified. -->
      <data
              android:scheme="https"
              android:host="**my.domain.com**"
              android:pathPrefix="/test" />
  </intent-filter>

手動測試意圖鏈接是否正常工作:

您可以在模擬器運行的情況下運行此命令,它應該會打開應用程序:

adb shell am start -W -a android.intent.action.VIEW -d "https://my.domain.com/test?code=abcde"

手動測試意圖鏈接

  1. 支持更新的域驗證流程
  • adb shell am compat enable 175408749 PACKAGE_NAME
  1. 重置設備上 Android App Links 的 state
  • adb shell pm set-app-links --package PACKAGE_NAME 0 all
  1. 調用域驗證過程
  • adb shell pm verify-app-links --re-verify PACKAGE_NAME
    運行此命令后,等待至少一分鍾讓應用程序驗證您的域至關重要。
  1. 查看驗證結果
  • adb shell pm get-app-links PACKAGE_NAME

該命令的 output 類似如下:

com.example.pkg:
    ID: 01234567-89ab-cdef-0123-456789abcdef
    Signatures: [***]
    Domain verification state:
      my.domain.com: verified
      sub.example.com: legacy_failure
      example.net: verified
      example.org: 1026

之后你對 go 很好,你的意圖鏈接將在 android 12 及更低版本上工作。

最終測試以檢查您是否已正確設置所有內容
跑:

adb shell am start -W -a android.intent.action.VIEW -d "https://my.domain.com/test?code=abcde"

資料來源: https://developer.android.com/training/app-links/verify-site-associations

 <activity
        android:name=".DeeplinkActivity"
        android:exported="true"
        android:launchMode="singleTask"
        android:screenOrientation="portrait">
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="*.example.com"
                android:scheme="https" />
        </intent-filter>

    </activity>

我已經執行了所有步驟,但仍然出現“example.org: 1026”錯誤。 我已經通過模擬器中的WIFI連接。 因此,我已將互聯網更改為移動數據,並且運行良好。 可能有人在模擬器上遇到這個問題會幫助它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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