【发布时间】:2018-05-14 07:50:50
【问题描述】:
【问题讨论】:
标签: alexa alexa-skills-kit alexa-skill
【问题讨论】:
标签: alexa alexa-skills-kit alexa-skill
如何向 Alexa Card 添加图片?
首页卡片可以包含单个图像。在这种情况下,您提供 标题、文本和两个 URL(一个小版本和一个大版本) 要显示的图像。
请注意,字符总数(标题、内容和两者 卡片的 URL 组合)不能超过 8000。每个 URL 不能超过 2000 个字符。
要创建带有图像的卡片,请在 JSON 中包含 card 属性 回复:
将类型设置为标准。将标题和文本属性设置为 要显示的文本。请注意,这种类型的卡片使用文本属性,而不是 像 Simple 这样的内容属性。在 插入换行符的文本。包含一个带有 smallImageUrl 的图像对象 和 largeImageUrl 属性。将 smallImageUrl 和 largeImageUrl 设置为 要显示的图像的小版本和大版本的 URL。看 下面是有关图像格式、大小和托管的详细信息 要求。
{
"version": "1.0",
"response": {
"outputSpeech": {"type":"PlainText","text":"Your Car-Fu car is on the way!"},
"card": {
"type": "Standard",
"title": "Ordering a Car",
"text": "Your ride is on the way to 123 Main Street!\nEstimated cost for this ride: $25",
"image": {
"smallImageUrl": "https://carfu.com/resources/card-images/race-car-small.png",
"largeImageUrl": "https://carfu.com/resources/card-images/race-car-large.png"
}
}
}
}
使用 Java 库时:
创建一个 StandardCard 对象。调用对象的 setTitle() 和 setText() 方法来设置标题和内容。创建一个图像对象 并使用对象的 setSmallImageUrl() 和 setLargeImageUrl() 方法。将 Image 对象传递给 StandardCard 使用 setImage() 方法的对象。将 StandardCard 对象传递给 SpeechletResponse.newTellResponse() 或 SpeechletResponse.newAskResponse() 得到一个 SpeechletResponse 包括卡片。
【讨论】: