Added in API level 28
Deprecated in API level 35

SliceManager


public class SliceManager
extends Object

java.lang.Object
   ↳ android.app.slice.SliceManager


This class was deprecated in API level 35.
Slice framework has been deprecated, it will not receive any updates from ERROR(/android.os.Build.VANILLA_ICE_CREAM) and forward. If you are looking for a framework that sends displayable data from one app to another, consider using AppSearchManager.

Class to handle interactions with Slices.

The SliceManager manages permissions and pinned state for slices.

Summary

Constants

String CATEGORY_SLICE

Category used to resolve intents that can be rendered as slices.

String SLICE_METADATA_KEY

The meta-data key that allows an activity to easily be linked directly to a slice.

Public methods

Slice bindSlice(Uri uri, Set<SliceSpec> supportedSpecs)

Turns a slice Uri into slice content.

Slice bindSlice(Intent intent, Set<SliceSpec> supportedSpecs)

Turns a slice intent into slice content.

int checkSlicePermission(Uri uri, int pid, int uid)

Determine whether a particular process and user ID has been granted permission to access a specific slice URI.

List<Uri> getPinnedSlices()

Get the list of currently pinned slices for this app.

Set<SliceSpec> getPinnedSpecs(Uri uri)

Get the current set of specs for a pinned slice.

Collection<Uri> getSliceDescendants(Uri uri)

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

void grantSlicePermission(String toPackage, Uri uri)

Grant permission to access a specific slice Uri to another package.

Uri mapIntentToUri(Intent intent)

Turns a slice intent into a slice uri.

void pinSlice(Uri uri, Set<SliceSpec> specs)

Ensures that a slice is in a pinned state.

void revokeSlicePermission(String toPackage, Uri uri)

Remove permissions to access a particular content provider Uri that were previously added with grantSlicePermission(String, Uri) for a specific target package.

void unpinSlice(Uri uri)

Remove a pin for a slice.

Inherited methods

Constants

CATEGORY_SLICE

Added in API level 28
public static final String CATEGORY_SLICE

Category used to resolve intents that can be rendered as slices.

This category should be included on intent filters on providers that extend SliceProvider.

Constant Value: "android.app.slice.category.SLICE"

SLICE_METADATA_KEY

Added in API level 28
public static final String SLICE_METADATA_KEY

The meta-data key that allows an activity to easily be linked directly to a slice.

An activity can be statically linked to a slice uri by including a meta-data item for this key that contains a valid slice uri for the same application declaring the activity.

 <activity android:name="com.example.mypkg.MyActivity">
     <meta-data android:name="android.metadata.SLICE_URI"
                android:value="content://com.example.mypkg/main_slice" />
  </activity>
 

Constant Value: "android.metadata.SLICE_URI"

Public methods

bindSlice

Added in API level 28
public Slice bindSlice (Uri uri, 
                Set<SliceSpec> supportedSpecs)

Turns a slice Uri into slice content.

Parameters
uri Uri: The URI to a slice provider This value cannot be null.

supportedSpecs Set: List of supported specs. This value cannot be null.

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

See also:

bindSlice

Added in API level 28
public Slice bindSlice (Intent intent, 
                Set<SliceSpec> supportedSpecs)

Turns a slice intent into slice content. Is a shortcut to perform the action of both mapIntentToUri(android.content.Intent) and bindSlice(android.net.Uri, java.util.Set) at once.

Parameters
intent Intent: The intent associated with a slice. This value cannot be null.

supportedSpecs Set: List of supported specs. This value cannot be null.

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

checkSlicePermission

Added in API level 28
public int checkSlicePermission (Uri uri, 
                int pid, 
                int uid)

Determine whether a particular process and user ID has been granted permission to access a specific slice URI.

Parameters
uri Uri: The uri that is being checked. This value cannot be null.

pid int: The process ID being checked against. Must be > 0.

uid int: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.

Returns
int PackageManager#PERMISSION_GRANTED if the given pid/uid is allowed to access that uri, or PackageManager#PERMISSION_DENIED if it is not. Value is PackageManager.PERMISSION_GRANTED, or PackageManager.PERMISSION_DENIED

getPinnedSlices

Added in API level 28
public List<Uri> getPinnedSlices ()

Get the list of currently pinned slices for this app.

Returns
List<Uri> This value cannot be null.

getPinnedSpecs

Added in API level 28
public Set<SliceSpec> getPinnedSpecs (Uri uri)

Get the current set of specs for a pinned slice.

This is the set of specs supported for a specific pinned slice. It will take into account all clients and returns only specs supported by all.

Parameters
uri Uri

Returns
Set<SliceSpec> This value cannot be null.

See also:

getSliceDescendants

Added in API level 28
public 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.
This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
uri Uri: The uri to look for descendants under. This value cannot be null.

Returns
Collection<Uri> All slices within the space. This value cannot be null.

grantSlicePermission

Added in API level 28
public void grantSlicePermission (String toPackage, 
                Uri uri)

Grant permission to access a specific slice Uri to another package.

Parameters
toPackage String: The package you would like to allow to access the Uri. This value cannot be null.

uri Uri: The Uri you would like to grant access to. This value cannot be null.

mapIntentToUri

Added in API level 28
public 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 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 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 SliceProvider#onMapIntentToUri 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. This value cannot be null.

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

pinSlice

Added in API level 28
public void pinSlice (Uri uri, 
                Set<SliceSpec> specs)

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.

This may only be called by apps that are the default launcher for the device or the default voice interaction service. Otherwise will throw SecurityException.

Parameters
uri Uri: The uri of the slice being pinned. This value cannot be null.

specs Set: The list of supported SliceSpecs of the callback. This value cannot be null.

revokeSlicePermission

Added in API level 28
public void revokeSlicePermission (String toPackage, 
                Uri uri)

Remove permissions to access a particular content provider Uri that were previously added with grantSlicePermission(String, Uri) for a specific target package. The given Uri will match all previously granted Uris that are the same or a sub-path of the given Uri. That is, revoking "content://foo/target" will revoke both "content://foo/target" and "content://foo/target/sub", but not "content://foo". It will not remove any prefix grants that exist at a higher level.

Parameters
toPackage String: The package you would like to allow to access the Uri. This value cannot be null.

uri Uri: The Uri you would like to revoke access to. This value cannot be null.

unpinSlice

Added in API level 28
public void unpinSlice (Uri uri)

Remove a pin for a slice.

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

This may only be called by apps that are the default launcher for the device or the default voice interaction service. Otherwise will throw SecurityException.

Parameters
uri Uri: The uri of the slice being unpinned. This value cannot be null.