SliceViewManager

public abstract class SliceViewManager
extends Object

java.lang.Object
   ↳ androidx.slice.SliceViewManager


Class to handle interactions with Slices.

The SliceViewManager manages permissions and pinned state for slices.

Summary

Nested classes

interface SliceViewManager.SliceCallback

Class that listens to changes in Slices. 

Public methods

abstract Slice bindSlice(Intent intent)

Turns a slice intent into slice content.

abstract Slice bindSlice(Uri uri)

Turns a slice Uri into slice content.

static SliceViewManager getInstance(Context context)

Get a SliceViewManager.

abstract Collection<Uri> getSliceDescendants(Uri 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 void pinSlice(Uri uri)

Ensures that a slice is in a pinned state.

abstract void registerSliceCallback(Uri uri, SliceViewManager.SliceCallback callback)

Adds a callback to a specific slice uri.

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

Adds a callback to a specific slice uri.

abstract void unpinSlice(Uri uri)

Remove a pin for a slice.

abstract void unregisterSliceCallback(Uri uri, SliceViewManager.SliceCallback callback)

Removes a callback for a specific slice uri.

Inherited methods

Public methods

bindSlice

public abstract Slice bindSlice (Intent intent)

Turns a slice intent into slice content. Is a shortcut to perform the action of both mapIntentToUri(Intent) and bindSlice(Uri) 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.

bindSlice

public abstract Slice bindSlice (Uri uri)

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:

getInstance

public static SliceViewManager getInstance (Context context)

Get a SliceViewManager.

Parameters
context Context

Returns
SliceViewManager

getSliceDescendants

public abstract Collection<Uri> getSliceDescendants (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
uri Uri: The uri to look for descendants under.

Returns
Collection<Uri> All slices within the space.

mapIntentToUri

public abstract Uri mapIntentToUri (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 ContentResolver.getType(Uri) is SliceProvider.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 SliceManager.SLICE_METADATA_KEY, then the Uri specified there will be returned.
  3. Lastly, if the intent with SliceManager.CATEGORY_SLICE added resolves to a provider, then the provider will be asked to SliceProvider.onMapIntentToUri(Intent) and that result will be returned.
  4. If no slice is found, then null is returned.

Parameters
intent Intent: The intent associated with a slice.

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

pinSlice

public abstract void pinSlice (Uri uri)

Ensures that a slice is in a pinned state. <