可索引物件的通用建構器

貼紙

這是對貼紙或貼圖包進行索引以與 Gboard 整合時要包含的最重要屬性的概述。有關範例,請參閱 Github 上的App Indexing 範例

財產描述例子
name用於搜尋的名稱或關鍵字 - 不顯示。 “史努比貼紙包”
url連結到應用程式中的貼紙或貼紙包的 URL。 “http://sticker/pack/canonical/url/snoopy”
image貼紙或貼紙包圖形。為了獲得最佳影像質量,請使用大小為 320 像素或 500 像素的方形影像。 “http://link/to/the/image/bye”
description貼紙或貼紙包的輔助使用標籤。 “史努比貼紙一包”

例:貼紙包

// Build and index the sticker objects on first run after update or install
// to minimize lag between sticker install and stickers surfacing in Gboard.

FirebaseAppIndex.update(new Indexable.Builder("StickerPack")
   .setName("Snoopy Pack")
   .setImage("content://sticker/pack/canonical/image")
   // see: Support links to your app content section
   .setUrl("http://sticker/pack/canonical/url/snoopy")
   // Set the accessibility label for the sticker pack.
   .setDescription("A sticker pack of Snoopy")
   .put("hasSticker",
        new Indexable.Builder("Sticker")
          .setName("Hey")
          .setImage("http://link/to/the/image/hey")
          .setDescription("A Snoopy hey sticker.")
          .build(),
       new Indexable.Builder("Sticker")
          .setName("Bye")
          .setImage("http://link/to/the/image/bye")
          .setDescription("A Snoopy bye sticker.")
          .build())
   .build());

例:個人貼紙

Indexable[] stickers = new Indexable[]{
      new Indexable.Builder("Sticker")
   .setName("Hey")
   .setImage("http://www.snoopysticker.com?id=1234")
   // see: Support links to your app content section
   .setUrl("http://sticker/canonical/image/hey")
   // Set the accessibility label for the sticker.
   .setDescription("A sticker for hi")
   // Add search keywords.
   .put("keywords", "hey", "snoopy", "hi", "hello")
   .put("isPartOf",
        new Indexable.Builder("StickerPack")
          .setName("Snoopy Pack"))
          .build())
   .build()),
new Indexable.Builder("Sticker")
   .setName("Bye")
   .setImage("http://www.snoopysticker.com?id=4567")
   // see: Support links to your app content section
   .setUrl("http://sticker/canonical/image/bye")
   // Set the accessibility label for the sticker.
   .setDescription("A sticker for Bye")
   // Add search keywords.
   .put("keywords", "bye", "snoopy", "see ya", "good bye")
   .put("isPartOf",
        new Indexable.Builder("StickerPack")
          .setName("Snoopy Pack")
          .build())
   .build())};
// Make sure we update stickers in batch
FirebaseAppIndex.update(stickers);

訊息

這是應用程式在對訊息建立索引時應指定的最重要屬性的概述。

財產描述例子
url連結到應用程式中訊息的 URL。 “myapp://messages/42”
name郵件的主旨行,或直接是郵件本身(如果沒有單獨的主旨行)。 “回覆:午餐”
text選修的。訊息正文(如果適用)。對於沒有單獨主題行的即時訊息類型的訊息,請使用「名稱」(請參閱上文)。 “你有空吃午餐嗎?”
dateReceived對於傳入訊息,收到訊息的時間。新日期(2016, 6, 2, 23, 43, 00)
dateSent發送訊息的時間(對於傳出訊息)。新日期(2016, 6, 2, 23, 43, 00)
isPartOf.id訊息所屬的對話或線程的 ID。 “42”
sender訊息的發送者。
sender.name寄件人的姓名。 “愛麗絲”
sender.url選修的。連結到應用程式中的人員的 URL。 “http://example.net/profiles/alice”
sender.image選修的。寄件者的圖像。可以使用 Web URL 或內容 URI。 “http://example.net/alice.jpg”
sender.email選修的。寄件者的電子郵件地址。 “alice@example.net”
sender.telephone選修的。寄件者的電話號碼。 “+16502530000”
sender.isSelf指示使用者是否為寄件者。預設為 false。錯誤的
recipient訊息的一個或多個收件人。
recipient.name收件人姓名。 “鮑伯”
recipient.url選修的。連結到應用程式中的人員的 URL。 “http://example.net/profiles/bob”
recipient.image選修的。收件人的映像。可以使用 Web URL 或內容 URI。 “http://example.net/bob.jpg”
recipient.email選修的。寄件者的電子郵件地址。 “鮑勃@example.net”
recipient.telephone選修的。寄件者的電話號碼。 “+16502530000”
recipient.isSelf指示使用者是否為收件者。預設為 false。真的
messageAttachment選修的。郵件的一個或多個附件。
messageAttachment.name郵件附件的名稱。 “貼紙”
messageAttachment.image代表附件的圖像。可以使用 Web URL 或內容 URI。 “http://example.net/stickers/23.png”

範例:傳入訊息

Indexable message = Indexables.messageBuilder()
    .setUrl("myapp://messages/42")
    .setText("Are you free for lunch?")
    .setDateReceived(new Date(2016, 6, 2, 23, 44, 00))
    .setIsPartOf(Indexables.conversationBuilder().setId("42")
    .setSender(Indexables.personBuilder()
        .setName("Alice")
        .setImage("http://example.net/alice.jpg")
        .setEmail("alice@example.net")
        .setTelephone("+16502530000"))
    .setRecipient(Indexables.personBuilder()
        .setName("Bob")
        .setImage("http://example.net/bob.jpg")
        .setEmail("bob@people.net")
        .setTelephone("+16502530000")
        .setIsSelf(true))
    .build();
 

對於電子郵件訊息,請改用Indexables.emailMessageBuilder() 。支援的欄位沒有區別,但結果 UI 會有所不同(例如突出顯示電子郵件的主題行)。

筆記

這是應用程式在為筆記建立索引時應指定的最重要屬性的概述。

財產描述例子
url連結到應用程式中的註釋的 URL。 “myapp://notes/42”
name註釋的標題,或直接註釋文字本身(如果沒有單獨的標題)。 “購物清單”
text選修的。註釋的文字(如果適用)。對於沒有單獨標題的註釋,請使用「名稱」(請參閱上文)。 “牛排、麵食、葡萄酒”
image代表註釋的圖像。可以使用 Web URL 或內容 URI。 “http://example.net/shopping.jpg”
dateCreated筆記的創建時間。新日期(2016, 6, 2, 23, 43, 00)
author選修的。筆記的作者。
author.name筆記作者的姓名。 “鮑伯”

範例:註釋

Indexable note = Indexables.noteDigitalDocumentBuilder()
    .setUrl("myapp://notes/42")
    .setName("Shopping list")
    .setText("steak, pasta, wine")
    .setImage("http://example.net/shopping.jpg")
    .setDateCreated(new Date(2016, 6, 2, 23, 43, 00))
    .build();