SliceViewManager
@RequiresApi(value = 19)
abstract class SliceViewManager
Class to handle interactions with Slices.
The SliceViewManager manages permissions and pinned state for slices.
Summary
Nested types |
|---|
interface SliceViewManager.SliceCallbackClass that listens to changes in |
Public functions |
|
|---|---|
abstract Slice? |
Turns a slice intent into slice content. |
abstract Slice? |
Turns a slice Uri into slice content. |
java-static SliceViewManager |
getInstance(context: Context)Get a |
abstract (Mutable)Collection<Uri!> |
Obtains a list of slices that are descendants of the specified Uri. |
abstract Uri? |
mapIntentToUri(intent: Intent)Turns a slice intent into a slice uri. |
abstract Unit |
Ensures that a slice is in a pinned state. |
abstract Unit |
registerSliceCallback(uri: Uri, callback: SliceViewManager.SliceCallback)Adds a callback to a specific slice uri. |
abstract Unit |
registerSliceCallback(Adds a callback to a specific slice uri. |
abstract Unit |
unpinSlice(uri: Uri)Remove a pin for a slice. |
abstract Unit |
unregisterSliceCallback(Removes a callback for a specific slice uri. |
Public functions
bindSlice
abstract fun bindSlice(intent: Intent): Slice?
Turns a slice intent into slice content. Is a shortcut to perform the action of both mapIntentToUri and bindSlice at once.
| Parameters | |
|---|---|
intent: Intent |
The intent associated with a slice. |
| Returns | |
|---|---|
Slice? |
The Slice provided by the app or null if none is given. |
| See also | |
|---|---|
Slice |
|
onMapIntentToUri |
|
Intent |
bindSlice
abstract fun bindSlice(uri: Uri): Slice?
Turns a slice Uri into slice content.
| Parameters | |
|---|---|
uri: Uri |
The URI to a slice provider |
| Returns | |
|---|---|
Slice? |
The Slice provided by the app or null if none is given. |
| See also | |
|---|---|
Slice |
getInstance
java-static fun getInstance(context: Context): SliceViewManager
Get a SliceViewManager.
getSliceDescendants
@WorkerThread
abstract fun getSliceDescendants(uri: Uri): (Mutable)Collection<Uri!>
Obtains a list of slices that are descendants of the specified Uri.
Not all slice providers will implement this functionality, in which case, an empty collection will be returned.
| Parameters | |
|---|---|
uri: Uri |
The uri to look for descendants under. |
| Returns | |
|---|---|
(Mutable)Collection<Uri!> |
All slices within the space. |
| See also | |
|---|---|
onGetSliceDescendants |
mapIntentToUri
abstract fun mapIntentToUri(intent: Intent): Uri?
Turns a slice intent into a slice uri. Expects an explicit intent.
This goes through a several stage resolution process to determine if any slice can represent this intent.
- If the intent contains data that
getTypeisSLICE_TYPEthen the data will be returned. - If the intent explicitly points at an activity, and that activity has meta-data for key
SLICE_METADATA_KEY, then the Uri specified there will be returned. - Lastly, if the intent with
CATEGORY_SLICEadded resolves to a provider, then the provider will be asked toonMapIntentToUriand that result will be returned. - If no slice is found, then
nullis returned.
| Parameters | |
|---|---|
intent: Intent |
The intent associated with a slice. |
| Returns | |
|---|---|
Uri? |
The Slice Uri provided by the app or null if none exists. |
| See also | |
|---|---|
Slice |
|
onMapIntentToUri |
|
Intent |
pinSlice
abstract fun pinSlice(uri: Uri): Unit
Ensures that a slice is in a pinned state.
Pinned state is not persisted across reboots, so apps are expected to re-pin any slices they still care about after a reboot.
| Parameters | |
|---|---|
uri: Uri |
The uri of the slice being pinned. |
| See also | |
|---|---|
onSlicePinned |
registerSliceCallback
abstract fun registerSliceCallback(uri: Uri, callback: SliceViewManager.SliceCallback): Unit
Adds a callback to a specific slice uri.
This is a convenience method that performs a few slice actions at once. It will put the slice in a pinned state since there is a callback attached. It will also listen for content changes, when a content change is observed, the android system will bind the new slice and provide it to all registered SliceCallbacks.
This will not trigger a bindSlice immediately, it will only perform a bind and pass it to the callback after a change occurs. To avoid race conditions and missing data, callers should call bindSlice immediately after calling registerSliceCallback so that it has the current slice.
| Parameters | |
|---|---|
uri: Uri |
The uri of the slice being listened to. |
callback: SliceViewManager.SliceCallback |
The listener that should receive the callbacks. |
| See also | |
|---|---|
onSlicePinned |
registerSliceCallback
abstract fun registerSliceCallback(
uri: Uri,
executor: Executor,
callback: SliceViewManager.SliceCallback
): Unit
Adds a callback to a specific slice uri.
This is a convenience that performs a few slice actions at once. It will put the slice in a pinned state since there is a callback attached. It will also listen for content changes, when a content change observes, the android system will bind the new slice and provide it to all registered SliceCallbacks.
| Parameters | |
|---|---|
uri: Uri |
The uri of the slice being listened to. |
callback: SliceViewManager.SliceCallback |
The listener that should receive the callbacks. |
| See also | |
|---|---|
onSlicePinned |
unpinSlice
abstract fun unpinSlice(uri: Uri): Unit
Remove a pin for a slice.
If the slice has no other pins/callbacks then the slice will be unpinned.
| Parameters | |
|---|---|
uri: Uri |
The uri of the slice being unpinned. |
| See also | |
|---|---|
pinSlice |
|
onSliceUnpinned |
unregisterSliceCallback
abstract fun unregisterSliceCallback(
uri: Uri,
callback: SliceViewManager.SliceCallback
): Unit
Removes a callback for a specific slice uri.
Removes the app from the pinned state (if there are no other apps/callbacks pinning it) in addition to removing the callback.
| Parameters | |
|---|---|
uri: Uri |
The uri of the slice being listened to |
callback: SliceViewManager.SliceCallback |
The listener that should no longer receive callbacks. |
| See also | |
|---|---|
registerSliceCallback |