androidandroid-homebuttongoogle-assistant-sdk

Starting Google Assistant / What's on my screen from onClick of button?


I want to start Google Assistant with a query (or without any) when the user clicks a button, could not find any reference to doing this task.

I tried calling the following function, as I found in the documentation of Google Assistant but I do not understand how to use it for my Application:

@Override
public void onProvideAssistContent(AssistContent assistContent) {
  super.onProvideAssistContent(assistContent);

  String structuredJson = new JSONObject()
       .put("@type", "MusicRecording")
       .put("@id", "https://example.com/music/recording")
       .put("name", "Album Title")
       .toString();

  assistContent.setStructuredData(structuredJson);
}

It does nothing, even when I long press home screen button to open Google Assistant, and select option what's on my screen it shows nothing.

If this is not possible, can I add the same action as Long Press Home does, i.e. open Google Assistant; to my button?


Solution

  • This method is for the on-screen reading feature "What's on my screen?" It can help to parse content by giving additional context.

    As of now there is no programmable way to activate the Assistant in the normal manner. It doesn't have to be as the process is straightforward for users.

    You can implement an Assistant-like intent receiver for your app, so it'll be called when users long press. However, it would override that for all apps, which would not be a great experience.

    There is a Google Assistant SDK for embedding it into apps and devices. You can use the gRPC calls to send audio or text requests to the Google Assistant and get back a response. It is just a network API, so there's no UI included.