Last active
July 16, 2019 18:49
-
-
Save ElifBon/eb9872c2822b0fb82b5f4363afbc9312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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