public abstract class SliceProvider
extends ContentProvider

   ↳ android.content.ContentProvider
     ↳ androidx.slice.SliceProvider

A SliceProvider allows an app to provide Slices to the Android OS. A slice is a piece of app content and actions that can be displayed outside of the app in Android system surfaces or within another app. Slices are identified by a Uri and a SliceProvider allows your app to provide a slice based on a uri.

The primary method to implement in SliceProvider is onBindSlice(Uri) which is called whenever something wants to display a slice from your app. An app can have multiple slices all served from the same slice provider, the Uri passed to onBindSlice will identify the specific slice being requested.

 public MySliceProvider extends SliceProvider {

      public Slice onBindSlice(Uri sliceUri) {
          String path = sliceUri.getPath();
          switch (path) {
              case "/weather":
                  return createWeatherSlice(sliceUri);
              case "/traffic":
                  return createTrafficSlice(sliceUri);
          return null;

Slices are constructed with TemplateSliceBuilders.

Slices are not currently live content. They are bound once and shown to the user. If the content in the slice changes due to user interaction or an update in the data being displayed, then ContentResolver.notifyChange(Uri, ContentObserver) should be used to notify the system to request the latest slice from the app.

The provider needs to be declared in the manifest to provide the authority for the app. The authority for most slices is expected to match the package of the application.

     android:authorities="" />

Slices can also be identified by an intent. To link an intent with a slice, the slice provider must have an IntentFilter matching the slice intent. When a slice is being requested via an intent, onMapIntentToUri(Intent) will be called and is expected to return an appropriate Uri representing the slice.

         <action android:name="android.intent.action.MY_SLICE_INTENT" />
         <category android:name="" />

See also:


Inherited constants

Public constructors

SliceProvider(String... autoGrantPermissions)

A version of constructing a SliceProvider that allows autogranting slice permissions to apps that hold specific platform permissions.


Public methods

void attachInfo(Context context, ProviderInfo info)
final int bulkInsert(Uri uri, ContentValues[] values)
Bundle call(String method, String arg, Bundle extras)

Handles the call to SliceProvider.

final Uri canonicalize(Uri url)
final int delete(Uri uri, String selection, String[] selectionArgs)
List<Uri> getPinnedSlices()

Returns a list of slice URIs that are currently pinned.

final String getType(Uri uri)
final Uri insert(Uri uri, ContentValues values)
abstract Slice onBindSlice(Uri sliceUri)

Implemented to create a slice.

final boolean onCreate()
PendingIntent onCreatePermissionRequest(Uri sliceUri, String callingPackage)

Called when an app requests a slice it does not have write permission to the uri for.

abstract boolean onCreateSliceProvider()

Implement this to initialize your slice provider on startup.

Collection<Uri> onGetSliceDescendants(Uri uri)

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

Uri onMapIntentToUri(Intent intent)

This method must be overridden if an IntentFilter is specified on the SliceProvider.

void onSlicePinned(Uri sliceUri)

Called to inform an app that a slice has been pinned.

void onSliceUnpinned(Uri sliceUri)

Called to inform an app that a slices is no longer pinned.

final Cursor query(Uri uri, String[] projection, Bundle queryArgs, CancellationSignal cancellationSignal)
final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal)
final int update(Uri uri, ContentValues values, String selection, String[] selectionArgs)

Inherited methods