Assistant sharing

Users on Android phones can ask the Google Assistant to share app content with another user using a voice command like "Hey Google, send this to Jane". Based on the first user's system options, the Assistant may then incorporate text from the screen or a device screenshot in the shared content.

The Assistant inserts a selected photo into a message when
            prompted.
Figure 1. Assistant shares a photo with a contact

This method of sharing is often sufficient, but users who receive content shared from your app might not re-enter the app to view content. You can provide the Assistant with structured information about the current foreground content by implementing the onProvideAssistContent() method.

This process helps maintain the structure of data as it's shared to another user. Users who receive shared app content can then be deep linked or receive content directly, instead of as text or as a screenshot.

We recommend you implement onProvideAssistContent() for any sharable entity in your app.

Providing contextual content

You only need to implement onProvideAssistContent() for the final app activity in the user's task flow after invoking the App Action. For example, in a CREATE_MONEY_TRANSFER flow, you would implement the method in the final screen showing the receipt; you wouldn't need to implement it for any in-progress or preview screens.

Provide contextual information as a JSON-LD object in the structuredData field. The following code snippet shows an example of logging contextual content:

Java
@Override
public void onProvideAssistContent(AssistantContent outContent) {
  super.onProvideAssistContent(outContent);

  // JSON-LD object based on Schema.org structured data
  outContent.structuredData = new JSONObject()
          .put("@type", "MenuItem")
          .put("name", "Blueberry Crisp Iced Signature Latte")
          .put("url", "https://mysite.com/menuitems/12345a")
          .toString();
}
      
Kotlin
override fun onProvideAssistContent(outContent: AssistContent) {
    super.onProvideAssistContent(outContent)

    // JSON-LD object based on Schema.org structured data
    outContent.structuredData = JSONObject()
            .put("@type", "MenuItem")
            .put("name", "Blueberry Crisp Iced Signature Latte")
            .put("url", "https://mysite.com/menuitems/12345a")
            .toString()
}
      

Although we recommend providing as much data as possible about each entity, we require the following fields:

  • @type
  • .name
  • .url (only required if the content is URL-addressable)

To learn more about using onProvideAssistContent(), see the Optimizing Contextual Content for the Assistant guide in the Android developer documentation.