简体   繁体   English

如何让谷歌助手识别我的自定义意图?

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

I have the actions xml referenced in my manifest as well as my slice provider我的清单和切片提供程序中引用了操作 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>

My actions xml references my slice uris and my query patterns我的操作 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>

When hovering over the UnitStatusQueries, I see the values in my string array将鼠标悬停在 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>

I have granted assistant permissions我已授予助理权限

 @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
    }

I am confident my slice provider works since running the Google Assistant test tool and the App Actions test tool correctly shows the slices in Google Assistant.自从运行 Google Assistant 测试工具和 App Actions 测试工具正确显示 Google Assistant 中的切片后,我确信我的切片提供程序可以正常工作。

The final piece of the puzzle is actually getting Google Assistant to recognize the query and show my slice (outside of the test tools).难题的最后一块实际上是让 Google 助理识别查询并显示我的切片(在测试工具之外)。 I have deployed several builds for internal testing but nothing seems to work.我已经为内部测试部署了几个版本,但似乎没有任何效果。 Every time I try to use one of these invocation phrases I just get search results or the app opens.每次我尝试使用其中一个调用短语时,我都会得到搜索结果或应用程序打开。 I have tried combinations of: "Hey google, open [my app] and view unit status" "Hey google, view unit status" "Hey google, is my unit open?"我尝试过以下组合:“嘿 google,打开 [我的应用程序] 并查看单元状态”“嘿 google,查看单元状态”“嘿 google,我的单元打开了吗?”

Any insight would be greatly appreciated.任何见解将不胜感激。

I think there was just a misunderstanding on my end as to how the testing of Google Assistant and Slices are supported.我认为我对如何支持 Google Assistant 和 Slices 的测试存在误解。 Based on this link below I have determined my code is working correctly and the app actions will not be testable (outside of the app actions test tool) until the app is deployed.根据下面的此链接,我确定我的代码工作正常,并且在部署应用程序之前,应用程序操作将无法测试(在应用程序操作测试工具之外)。 https://github.com/actions-on-google/appactions-fitness-kotlin/issues/8 https://github.com/actions-on-google/appactions-fitness-kotlin/issues/8

One thing that was causing confusion for me was the invocation name I used when creating my app preview.让我感到困惑的一件事是我在创建应用预览时使用的调用名称。 I didn't put in my full app name when creating the preview, which made it so when I used the full app name with Google Assistant, my queries were not recognized.创建预览时我没有输入我的完整应用程序名称,因此当我在 Google 助理中使用完整的应用程序名称时,我的查询无法识别。

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

相关问题 我如何获得使用 Google Place Autocomplete 的意图? - how do I get my intent to work with Google Place Autocomplete? 如何使用Google Assistant触发我的申请 - How do I use Google assistant to trigger my application 将Intent从Google Assistant发送到我的智能手机 - Sending an Intent from Google Assistant to my smartphone Google 助手无法从 BII“actions.intent.GET_ACCOUNT”获取自定义帐户名 - Google assistant can't get custom account name from BII “actions.intent.GET_ACCOUNT” 如何从Google Assistant获取文本,以便我可以解析文本以执行某些操作? - How can I get text from Google Assistant so that I can parse the text to do certain action? Google Assistant是否与我的自定义应用程序集成? - Google Assistant integration with my custom app? 触发 Google Assistant 命令时如何获取回调? - How can I get the callback when Google Assistant command is triggered? 如何使用 actions.intent.OPEN_APP_FEATURE 设置助手快捷方式建议? - How do I set up assistant shortcut suggestions with actions.intent.OPEN_APP_FEATURE? 如何从Android手机向配对的Google Glass发送Intent - How do I send an Intent from my Android phone to a paired Google Glass 如何从我的主配置文件中的应用程序获取我的工作配置文件应用程序的启动意图? - How do i get the launch intent for my work profile app from my app in the primary profile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM