Skip to content

Instantly share code, notes, and snippets.

@ElifBon

ElifBon/onBindSlice.kt

Last active Jul 16, 2019
Embed
What would you like to do?
/**
* Construct the Slice and bind data if available.
*/
override fun onBindSlice(sliceUri: Uri): Slice? {
// Note: you should switch your build.gradle dependency to
// slice-builders-ktx for a nicer interface in Kotlin.
val context = context ?: return null
val activityAction = createActivityAction() ?: return null
return if (sliceUri.path == "/hello") {
// Path recognized. Customize the Slice using the androidx.slice.builders API.
// Note: ANR and StrictMode are enforced here so don't do any heavy operations.
// Only bind data that is currently available in memory.
ListBuilder(context, sliceUri, ListBuilder.INFINITY)
.addRow(
ListBuilder.RowBuilder()
.setTitle("URI found.")
.setPrimaryAction(activityAction)
)
.build()
} else {
// Error: Path not found.
ListBuilder(context, sliceUri, ListBuilder.INFINITY)
.addRow(
ListBuilder.RowBuilder()
.setTitle("URI not found.")
.setPrimaryAction(activityAction)
)
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.