Added in API level 28
Deprecated in API level 35

SliceManager


open class SliceManager
kotlin.Any
   ↳ android.app.slice.SliceManager

Class to handle interactions with Slices.

The SliceManager manages permissions and pinned state for slices.

Summary

Constants
static String

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

static String

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

Public methods
open Slice?
bindSlice(uri: Uri, supportedSpecs: MutableSet<SliceSpec!>)

Turns a slice Uri into slice content.

open Slice?
bindSlice(intent: Intent, supportedSpecs: MutableSet<SliceSpec!>)

Turns a slice intent into slice content.

open Int
checkSlicePermission(uri: Uri, pid: Int, uid: Int)

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

open MutableList<Uri!>

Get the list of currently pinned slices for this app.

open MutableSet<SliceSpec!>

Get the current set of specs for a pinned slice.

open MutableCollection<Uri!>

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

open Unit
grantSlicePermission(toPackage: String, uri: Uri)

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

open Uri?

Turns a slice intent into a slice uri.

open Unit
pinSlice(uri: Uri, specs: MutableSet<SliceSpec!>)

Ensures that a slice is in a pinned state.

open Unit
revokeSlicePermission(toPackage: String, uri: Uri)

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

open Unit

Remove a pin for a slice.

Constants

CATEGORY_SLICE

Added in API level 28
static val CATEGORY_SLICE: String

Deprecated: Deprecated in Java.

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

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

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

SLICE_METADATA_KEY

Added in API level 28
static val SLICE_METADATA_KEY: String

Deprecated: Deprecated in Java.

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>
  
Value: "android.metadata.SLICE_URI"

Public methods

bindSlice

Added in API level 28
open fun bindSlice(
    uri: Uri,
    supportedSpecs: MutableSet<SliceSpec!>
): Slice?

Deprecated: Deprecated in Java.

Turns a slice Uri into slice content.

Parameters
uri Uri: The URI to a slice provider This value cannot be null.
supportedSpecs MutableSet<SliceSpec!>: List of supported specs. This value cannot be null.
Return
Slice? The Slice provided by the app or null if none is given.

bindSlice

Added in API level 28
open fun bindSlice(
    intent: Intent,
    supportedSpecs: MutableSet<SliceSpec!>
): Slice?

Deprecated: Deprecated in Java.

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 MutableSet<SliceSpec!>: List of supported specs. This value cannot be null.
Return
Slice? The Slice provided by the app or null if none is given.

checkSlicePermission

Added in API level 28
open fun checkSlicePermission(
    uri: Uri,
    pid: Int,
    uid: Int
): Int

Deprecated: Deprecated in Java.

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.
Return
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 android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getPinnedSlices

Added in API level 28
open fun getPinnedSlices(): MutableList<Uri!>

Deprecated: Deprecated in Java.

Get the list of currently pinned slices for this app.

Return
MutableList<Uri!> This value cannot be null.

getPinnedSpecs

Added in API level 28
open fun getPinnedSpecs(uri: Uri!): MutableSet<SliceSpec!>

Deprecated: Deprecated in Java.

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.

Return
MutableSet<SliceSpec!> This value cannot be null.

getSliceDescendants

Added in API level 28
open fun getSliceDescendants(uri: Uri): MutableCollection<Uri!>

Deprecated: Deprecated in Java.

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.
Return
MutableCollection<Uri!> All slices within the space. This value cannot be null.

grantSlicePermission

Added in API level 28
open fun grantSlicePermission(
    toPackage: String,
    uri: Uri
): Unit

Deprecated: Deprecated in Java.

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
open fun mapIntentToUri(intent: Intent): Uri?

Deprecated: Deprecated in Java.

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.
Return
Uri? The Slice Uri provided by the app or null if none exists.

pinSlice

Added in API level 28
open fun pinSlice(
    uri: Uri,
    specs: MutableSet<SliceSpec!>
): Unit

Deprecated: Deprecated in Java.

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 MutableSet<SliceSpec!>: The list of supported SliceSpecs of the callback. This value cannot be null.

revokeSlicePermission

Added in API level 28
open fun revokeSlicePermission(
    toPackage: String,
    uri: Uri
): Unit

Deprecated: Deprecated in Java.

Remove permissions to access a particular content provider Uri that were previously added with grantSlicePermission 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
open fun unpinSlice(uri: Uri): Unit

Deprecated: Deprecated in Java.

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.