Android:提升使用者搜尋產品的機會與便利性,App Indexing實作II

Xavier Yin
KKday Tech Blog
Published in
3 min readAug 3, 2018

上篇文章提到了App indexing可以將你的應用程式在Google search中建立索引,爾後搜尋出來的結果,只要使用者已安裝你的應用程式,點擊搜尋結果的鏈結,就能無縫地進入該內容,而非網頁。但App indexing不僅能針對搜尋網頁,還可以幫助你的使用者在個人裝置中,找尋公開或個人化的內容,甚至可以透過Google search bar的自動完成,快速地找到他們所要的內容(如下圖所示),在這篇文章就是要來實作這個功能。

Google Search搜尋「KKday 迪士尼」,自動完成則會記錄該關鍵字結果。

實作分爲下列步驟:

Build gradle加入Firebase app indexing 服務,如下圖所示。

dependencies {
...
compile 'com.google.firebase:firebase-appindexing:11.4.2'
...
}

匯入相關類別,如下圖所示。

import com.google.firebase.appindexing.FirebaseAppIndex
import com.google.firebase.appindexing.Indexable

呼叫App indexing API,如下圖所示。

val indexableProductInfo = Indexable
.Builder()
.setName("Your product name")
.setUrl("https://xxx.xxx.xxx.....")
.setDescription("Your product description")
.setKeywords("Your product keywords")
.build()
FirebaseAppIndex.getInstance().update(indexableProductInfo)

測試方式如同Deep Link,這邊則不多做贅述。

--

--