SliceViewManager
public
abstract
class
SliceViewManager
extends Object
java.lang.Object | |
↳ | androidx.slice.SliceViewManager |
Class to handle interactions with Slice
s.
The SliceViewManager manages permissions and pinned state for slices.
Summary
Nested classes | |
---|---|
interface |
SliceViewManager.SliceCallback
Class that listens to changes in |
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 |
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. |
See also:
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.
- If the intent contains data that
ContentResolver.getType(Uri)
isSliceProvider.SLICE_TYPE
then the data will be returned. - 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. - Lastly, if the intent with
SliceManager.CATEGORY_SLICE
added resolves to a provider, then the provider will be asked toSliceProvider.onMapIntentToUri(Intent)
and that result will be returned. - 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.
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:
registerSliceCallback
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.SliceCallback
s.
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:
registerSliceCallback
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.SliceCallback
s.
Parameters | |
---|---|
uri |
Uri : The uri of the slice being listened to. |
executor |
Executor |
callback |
SliceViewManager.SliceCallback : The listener that should receive the callbacks. |
See also:
unpinSlice
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
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. |
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-02-24 UTC.