4

I am trying to implement a Slice in android from the guide given here. However the implementation here can only be viewed through the Slice Viewer app. There is no change in the app when I run it. I think I am missing something which has to be added to the layout file I want my slice to be viewed in. But that's just a guess.

I am also unable to understand how to implement the SliceViewApi to view my Slice.

Any help would be appreciated!

AdamK
  • 21,199
  • 5
  • 42
  • 58
speedster01
  • 433
  • 3
  • 19

3 Answers3

2

At time of writing, Slices are not displayed anywhere in the Android system or Google apps yet as per the docs:

Slices will start appearing soon for users, but you can start building today.

As you noted, the actual implementation to render/display a Slice, called SliceView, is already available, however no apps have actually implemented this yet (at least not to my knowledge). You could implement this yourself but there isn't much point if you only intend to display your own Slices (you could just use regular views then). The main use-case to implement SliceView yourself would be if you were a launcher type app and were looking to display Slices from other applications.

The Slice Viewer app demonstrates an implementation of SliceView but its main purpose for now is to let you build and test your Slices in preparation for other apps implementing SliceView.

At Google I/O 2018, in the Slices session, it was announced that the first system area for Slices to show will be Google Search to enhance app predictions. In the session, it was announced that this will be launching some time in 2018.

AdamK
  • 21,199
  • 5
  • 42
  • 58
1

I also had some trouble with the Slices guide and the SliceViewer and eventually found some mistakes in the SliceViewer. I fixed these in a fork that I made (https://github.com/roadmaptravel/android-SliceViewer). If you clone/download this fork and run it in Android Studio 3.2 Canary 16 then you can add the demo slices by entering the following URI's in the SliceViewer:

Also something that's unclear in the Slice guide is that if you want to see your own Slice in the SliceViewer you can only use one of these 3 schemes: content, http or https. For example:

<provider
    android:name=".provider.SampleSliceProvider"
    android:authorities="com.example.android.sliceviewer"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.app.slice.category.SLICE" />

        <data
            android:host="sliceviewer.android.example.com"
            android:pathPrefix="/"
            android:scheme="https" />
    </intent-filter>
</provider>

Please let me know if this is of any help to you and if you have any other questions about Slices then don't hesitate to ask them.

Update: My changes are merged in the original SliceViewer repository (https://github.com/googlesamples/android-SliceViewer), so I would recommend to use that one (again).

Glenn85
  • 619
  • 1
  • 6
  • 14
0

Slice viewer can be created using SliceView widget, SliceViewManager and SliceLiveData.

Here are the steps to create basic slice viewer or slice presenter.

  • First Add SliceView to layout.

  • Then bind a slice to SliceView using SliceViewManager and the slice uri.

  • To display slice changes in slice viewer, use SliceLiveData to observe slice changes.

For complete sliceview example, you can check http://www.zoftino.com/android-slices-with-examples

Arnav Rao
  • 6,692
  • 2
  • 34
  • 31