in appindexing/app/src/main/java/com/google/firebase/example/appindexing/kotlin/AppIndexingUpdateService.kt [26:56]
override fun onHandleWork(intent: Intent) {
// TODO Insert your Indexable objects — for example, the recipe notes look as follows:
val indexableNotes = arrayListOf<Indexable>()
for (recipe in getAllRecipes()) {
val note = recipe.note
if (note != null) {
val noteToIndex = Indexables.noteDigitalDocumentBuilder()
.setName(recipe.title + " Note")
.setText(note.text)
.setUrl(recipe.noteUrl)
.build()
indexableNotes.add(noteToIndex)
}
}
if (indexableNotes.size > 0) {
val notesArr: Array<Indexable> = indexableNotes.toTypedArray()
// batch insert indexable notes into index
try {
Tasks.await(FirebaseAppIndex.getInstance(this).update(*notesArr))
} catch (e: ExecutionException) {
// update failed
} catch (e: InterruptedException) {
// await was interrupted
}
}
}