簡體   English   中英

如何讓谷歌助手識別我的自定義意圖?

[英]How do I get google assistant to recognize my custom intent?

我的清單和切片提供程序中引用了操作 xml

<application>
  <meta-data
    android:name="com.google.android.actions"
    android:resource="@xml/actions" />


<provider
      android:name=".sliceproviders.MyAppSliceProvider"
      android:authorities="com.company.app"
      android:exported="true"
      android:grantUriPermissions="true">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.app.slice.category.SLICE" />
      </intent-filter>
    </provider>

</application>

我的操作 xml 引用了我的切片 uris 和我的查詢模式

<actions>
  <action
    intentName="custom.actions.intent.UNIT_STATUS"
    queryPatterns="@array/UnitStatusQueries">
    <fulfillment
      fulfillmentMode="actions.fulfillment.SLICE"
      urlTemplate="content://com.company.app/unit_status" />
  </action>
</actions>

將鼠標懸停在 UnitStatusQueries 上時,我看到了字符串數組中的值

  <string-array name="UnitStatusQueries">
    <item>View unit status</item>
    <item>What is the status of my unit?</item>
    <item>Is my unit open?</item>
  </string-array>

我已授予助理權限

 @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    private fun grantAssistantPermissions() {
        getAssistantPackage()?.let { assistantPackage ->
            val sliceProviderUri = Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority("com.company.app")
                .build()
            androidx.slice.SliceManager.getInstance(this)
                .grantSlicePermission(assistantPackage, sliceProviderUri)
        }
    }


    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    private fun getAssistantPackage(): String? {
        val resolveInfoList = packageManager?.queryIntentServices(
            Intent(VoiceInteractionService.SERVICE_INTERFACE), 0
        )
        return resolveInfoList?.firstOrNull()?.serviceInfo?.packageName
    }

自從運行 Google Assistant 測試工具和 App Actions 測試工具正確顯示 Google Assistant 中的切片后,我確信我的切片提供程序可以正常工作。

難題的最后一塊實際上是讓 Google 助理識別查詢並顯示我的切片(在測試工具之外)。 我已經為內部測試部署了幾個版本,但似乎沒有任何效果。 每次我嘗試使用其中一個調用短語時,我都會得到搜索結果或應用程序打開。 我嘗試過以下組合:“嘿 google,打開 [我的應用程序] 並查看單元狀態”“嘿 google,查看單元狀態”“嘿 google,我的單元打開了嗎?”

任何見解將不勝感激。

我認為我對如何支持 Google Assistant 和 Slices 的測試存在誤解。 根據下面的此鏈接,我確定我的代碼工作正常,並且在部署應用程序之前,應用程序操作將無法測試(在應用程序操作測試工具之外)。 https://github.com/actions-on-google/appactions-fitness-kotlin/issues/8

讓我感到困惑的一件事是我在創建應用預覽時使用的調用名稱。 創建預覽時我沒有輸入我的完整應用程序名稱,因此當我在 Google 助理中使用完整的應用程序名稱時,我的查詢無法識別。

暫無
暫無

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

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