SliceViewManager


@RequiresApi(value = 19)
public abstract class SliceViewManager


Class to handle interactions with Slices.

The SliceViewManager manages permissions and pinned state for slices.

Summary

Nested types

Class that listens to changes in Slices.

Public methods

abstract @Nullable Slice

Turns a slice intent into slice content.

abstract @Nullable Slice

Turns a slice Uri into slice content.

static @NonNull SliceViewManager

Get a SliceViewManager.

abstract @NonNull Collection<Uri>

Obtains a list of slices that are descendants of the specified Uri.

abstract @Nullable Uri

Turns a slice intent into a slice uri.

abstract void

Ensures that a slice is in a pinned state.

abstract void

Adds a callback to a specific slice uri.

abstract void
registerSliceCallback(
    @NonNull Uri uri,
    @NonNull Executor executor,
    @NonNull SliceViewManager.SliceCallback callback
)

Adds a callback to a specific slice uri.

abstract void

Remove a pin for a slice.

abstract void

Removes a callback for a specific slice uri.

Public methods

bindSlice

Added in 1.1.0-alpha02
public abstract @Nullable Slice bindSlice(@NonNull Intent intent)

Turns a slice intent into slice content. Is a shortcut to perform the action of both mapIntentToUri and bindSlice at once.

Parameters
@NonNull Intent intent

The intent associated with a slice.

Returns
@Nullable Slice

The Slice provided by the app or null if none is given.

bindSlice

Added in 1.1.0-alpha02
public abstract @Nullable Slice bindSlice(@NonNull Uri uri)

Turns a slice Uri into slice content.

Parameters
@NonNull Uri uri

The URI to a slice provider

Returns
@Nullable Slice

The Slice provided by the app or null if none is given.

See also
Slice

getInstance

Added in 1.1.0-alpha02
public static @NonNull SliceViewManager getInstance(@NonNull Context context)

Get a SliceViewManager.

getSliceDescendants

Added in 1.1.0-alpha02
@WorkerThread
public abstract @NonNull Collection<UrigetSliceDescendants(@NonNull Uri 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
@NonNull Uri uri

The uri to look for descendants under.

Returns
@NonNull Collection<Uri>

All slices within the space.

mapIntentToUri

Added in 1.1.0-alpha02
public abstract @Nullable Uri mapIntentToUri(@NonNull Intent intent)

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.

  1. If the intent contains data that getType is SLICE_TYPE then the data will be returned.
  2. 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.
  3. Lastly, if the intent with CATEGORY_SLICE added resolves to a provider, then the provider will be asked to onMapIntentToUri and that result will be returned.
  4. If no slice is found, then null is returned.
Parameters
@NonNull Intent intent

The intent associated with a slice.

Returns
@Nullable Uri

The Slice Uri provided by the app or null if none exists.

pinSlice

Added in 1.1.0-alpha02
public abstract void pinSlice(@NonNull Uri uri)

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
@NonNull Uri uri

The uri of the slice being pinned.

See also
onSlicePinned

registerSliceCallback

Added in 1.1.0-alpha02
public abstract void registerSliceCallback(
    @NonNull Uri uri,
    @NonNull SliceViewManager.SliceCallback callback
)

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
@NonNull Uri uri

The uri of the slice being listened to.

@NonNull SliceViewManager.SliceCallback callback

The listener that should receive the callbacks.

See also
onSlicePinned

registerSliceCallback

Added in 1.1.0-alpha02
public abstract void registerSliceCallback(
    @NonNull Uri uri,
    @NonNull Executor executor,
    @NonNull SliceViewManager.SliceCallback callback
)

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
@NonNull Uri uri

The uri of the slice being listened to.

@NonNull SliceViewManager.SliceCallback callback

The listener that should receive the callbacks.

See also
onSlicePinned

unpinSlice

Added in 1.1.0-alpha02
public abstract void unpinSlice(@NonNull Uri uri)

Remove a pin for a slice.

If the slice has no other pins/callbacks then the slice will be unpinned.

Parameters
@NonNull Uri uri

The uri of the slice being unpinned.

unregisterSliceCallback

Added in 1.1.0-alpha02
public abstract void unregisterSliceCallback(
    @NonNull Uri uri,
    @NonNull SliceViewManager.SliceCallback callback
)

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
@NonNull Uri uri

The uri of the slice being listened to

@NonNull SliceViewManager.SliceCallback callback

The listener that should no longer receive callbacks.