Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.slice:slice-view:1.0.0-rc01

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

added in version 1.0.0
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

added in version 1.0.0
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

added in version 1.0.0
public static SliceViewManager getInstance (Context context)

Get a SliceViewManager.

Parameters
context Context

Returns
SliceViewManager

getSliceDescendants

added in version 1.0.0
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

added in version 1.0.0
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

added in version 1.0.0
public abstract void pinSlice (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
uri Uri: The uri of the slice being pinned.

registerSliceCallback

added in version 1.0.0
public abstract void registerSliceCallback (Uri uri, 
                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 SliceViewManager.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.

registerSliceCallback

added in version 1.0.0
public abstract void registerSliceCallback (Uri uri, 
                Executor executor, 
                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 SliceViewManager.SliceCallbacks.

Parameters
uri Uri: The uri of the slice being listened to.

executor Executor

callback SliceViewManager.SliceCallback: The listener that should receive the callbacks.

unpinSlice

added in version 1.0.0
public abstract void unpinSlice (Uri uri)

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.

unregisterSliceCallback

added in version 1.0.0
public abstract void unregisterSliceCallback (Uri uri, 
                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
uri Uri: The uri of the slice being listened to

callback SliceViewManager.SliceCallback: The listener that should no longer receive callbacks.