Class LinkPreview

  • LinkPreview is a card action that displays a preview card and smart chip within a host application.

  • Developers can customize the title shown in the link preview and smart chip using setLinkPreviewTitle() and setTitle(), respectively.

  • A preview card, created using CardService, provides detailed information about the linked content within the LinkPreview.

  • setPreviewCard() is used to attach this custom preview card to the LinkPreview action.

  • The printJson() method is available for debugging purposes to inspect the JSON representation of the LinkPreview object.

LinkPreview

Card action that displays a link preview card and smart chip in the host app. For more information, refer to Preview links with smart chips.

constdecoratedText=
CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');
constcardSection=CardService.newCardSection().addWidget(decoratedText);
constcard=CardService.newCardBuilder().addSection(cardSection).build();
constlinkPreview=CardService.newLinkPreview().setPreviewCard(card).setTitle(
'Smart chip title');

Methods

MethodReturn typeBrief description
printJson() StringPrints the JSON representation of this object.
setLinkPreviewTitle(title) LinkPreview Sets the title that displays in the link preview above the preview card.
setPreviewCard(previewCard) LinkPreview Sets the card that displays information about a link from a third-party or non-Google service.
setTitle(title) LinkPreview Sets the title that displays in the smart chip for the link preview.

Detailed documentation

printJson()

Prints the JSON representation of this object. This is for debugging only.

Return

String


setLinkPreviewTitle(title)

Sets the title that displays in the link preview above the preview card. If unset, the link preview displays the header of the PreviewCard.

constlinkPreview=
CardService.newLinkPreview().setLinkPreviewTitle('Link preview title');

Parameters

NameTypeDescription
titleStringThe title of the link preview.

Return

LinkPreview — This object, for chaining.


setPreviewCard(previewCard)

Sets the card that displays information about a link from a third-party or non-Google service.

constdecoratedText=
CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');
constcardSection=CardService.newCardSection().addWidget(decoratedText);
constcard=CardService.newCardBuilder().addSection(cardSection).build();
constlinkPreview=CardService.newLinkPreview().setPreviewCard(card).setTitle(
'Smart chip title');

Parameters

NameTypeDescription
previewCardCard The preview card.

Return

LinkPreview — This object, for chaining.


setTitle(title)

Sets the title that displays in the smart chip for the link preview. If unset, the smart chip displays the header of the PreviewCard.

constlinkPreview=CardService.newLinkPreview().setTitle('Smart chip title');

Parameters

NameTypeDescription
titleStringThe title of the smart chip.

Return

LinkPreview — This object, for chaining.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年12月02日 UTC.