Blog Infos
Author
Published
Topics
Author
Published
Android app tight integration with the assistant
What are Slices?

Slices examples

Implementation
Declaring the Slice in Shortcuts.xml
<capability android:name="actions.intent.OPEN_APP_FEATURE">
    <slice>
        <url-template
            android:name="content://com.example.android.app.provider/slice{?feature}" />

    </slice>
</capability>
Creating the SliceProvider
  • onBindSlice(), it takes a Uri, and what you need to do is map this Uri with your slice and return the Slice
  • onCreateSliceProvider(), you can do preliminary tasks, but something light, do not block the thread, and return true.
  • last but not least, you can show the Slice Authority, this is a unique name that will allow the system to trigger the Slice, see Grant Permission below.
class MySliceProvider : SliceProvider() {
    companion object {
        const val SLICE_AUTHORITY = "com.example.android.app.provider"
    }
    override fun onBindSlice(sliceUri: Uri?): Slice? {
        // you can filter the sliceUri here to provide the appropriate slice
        return createSlice()
    }
    override fun onCreateSliceProvider(): Boolean = true
}

 

Job Offers

Job Offers


    Android Developer

    Yoti Ltd
    Anywhere
    • Full Time
    apply now

    Android Entwicklerin Echtzeitkommunikation

    sipgate GmbH
    Germany
    • Full Time
    apply now

    Senior Android Engineer

    Busuu
    Madrid
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

, ,

The Evolution of Android Graphics in Android 12/13

Android 12 and 13 both added significant new capabilities to Android platform graphics, including RenderEffect, RuntimeShader, and more. At the same time, RenderScript has been deprecated and we’ve introduced the RenderScript Intrinsics Replacement Toolkit. This…
Watch Video

The Evolution of Android Graphics in Android 12/13

Daniel Galpin
Android Developer Advocate and Fast Talking YouTuber
Google

The Evolution of Android Graphics in Android 12/13

Daniel Galpin
Android Developer Ad ...
Google

The Evolution of Android Graphics in Android 12/13

Daniel Galpin
Android Developer Advocat ...
Google

Jobs

Declare SliceProvider in AndroidManifest
<application>
...
<provider android:name="MySliceProvider"
    android:authorities="com.example.android.app.provider"
    android:exported="true" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.app.slice.category.SLICE" />
    </intent-filter>
</provider>
Grant Slice permissions
private fun grantAssistantPermissions() {
    getAssistantPackage()?.let { assistantPackage ->
        val sliceProviderUri = Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(MySliceProvider.SLICE_AUTHORITY)
            .build()

        SliceManager.getInstance(this).grantSlicePermission(assistantPackage, sliceProviderUri)
    }
}
Creating a Slice
// SliceProvider
fun createSlice() {
    return list(...) {
        header {
            title = "My title"
            subtitle = "Subtitle"
            // Defines the primary action when slice is clicked
            primaryAction = SliceAction.create(...)
        }
        row { ... }
    }
}
Previewing with SliceViewer

Releases · android/user-interface-samples

adb install -r -t slice-viewer.apk

You can now execute the following command to start SliceViewer. Notice how the keyword slice has been prefixed to content.

adb shell am start -a android.intent.action.VIEW -d 
slice-content://com.example.android.app.provider/slice

example of slice viewer

Conclusion
Resources

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
In this part of our series on introducing Jetpack Compose into an existing project,…
READ MORE
blog
Nowadays authentication has become common in almost all apps. And many of us know…
READ MORE
blog
Collections are a set of interfaces and classes that implement highly optimised data structures.…
READ MORE

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu