Skip to content

Instantly share code, notes, and snippets.

@ElifBon
Last active July 16, 2019 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElifBon/eb9872c2822b0fb82b5f4363afbc9312 to your computer and use it in GitHub Desktop.
Save ElifBon/eb9872c2822b0fb82b5f4363afbc9312 to your computer and use it in GitHub Desktop.
/**
* 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