Topic covered:
-
Basic slices shared data through slices with activity
-
Advance Slices :
- Live List
- Grid
- Header
- Toggle Switches
- Multiple Actions passing
- Live Slider
- Live Progress Bar &
- Complex Slices
Follow the steps to get started with slices from blog: http://hiteshsahu.com/blogs/android_slices
Continuing in last post here I gone explain how to create Slices for your application. If you have not read it please go through my previous post Understanding Slices to get your setup ready.
You need to install Slice Viewer apk to view your slices. Download latest relase of slice viewer apk from https://github.com/googlesamples/android-SliceViewer/releases & install it using command:
adb install -r -t slice-viewer.apk
where :
- -r: replaces existing application
- -t: allow test packages
Now you can view your Slice by running the following command:
adb shell am start -a android.intent.action.VIEW -d slice-content://com.hiteshsahu.slicedemo/
It is pretty much like loading different pages of a website by changing URLS
For example:
- content://com.hiteshsahu.slicedemo/ : will gone load home slice
- content://com.hiteshsahu.slicedemo/about : will gone load about slice
- content://com.hiteshsahu.slicedemo/contact : will gone load contact slice
and so on see the result below.
Every time you gone launch a new slice with this adb command then that slice will be automatically get added in Slice Viewer demo app. Which you can see any time later.
Same can be achieve with the help of Android studio but I prefer command line tool. COmmand line tool is less complicate and less overhead.
If you have uninstalled sliceviewer.apk by drag and drop in Launcher app then chances are you might no longer will be able to install it back via adb command. This is a weird bug I found. In that case you will need to uninstall sliceviewer using this command.
adb uninstall com.example.android.sliceviewer
As already described in my previous post Understanding SLices you can use Android Studio to create Slices as shown in pic below:
- Install SliceViewer APK:
adb install -r -t slice-viewer.apk
- Download, Build, Install & Launch this project.
- Execute this command from adb termainal:
adb shell am start -a android.intent.action.VIEW -d slice-<uri_from_below>
For example to Launch Home screen from Slice execute. Note the "-" after slice.
adb shell am start -a android.intent.action.VIEW -d slice-content://com.hiteshsahu.slicedemo/
BasicSliceProvider
class contain example of how we can create aslice and use Peending Intent to send data to the App
Similarly replace <uri_from_below> with this uris to launch Slice mapped to screens.
-
home
content://com.hiteshsahu.slicedemo/
-
about
content://com.hiteshsahu.slicedemo/about
-
contact
content://com.hiteshsahu.slicedemo/contact
-
ERROR 404
content://com.hiteshsahu.slicedemo/etc :
Use this uri to launch complex slices with live data
-
SLICE WITH HEADER : this uri launch a Slice with a header and 3 custom Actions. Each action can be send to App with the help of Pending Intents. Click on Actions to see how App handle them.
content://com.hiteshsahu.slicedemo.advance/
-
SLICE WITH TOGGLE Show how to use toggle switch to turn on/off Wifi
content://com.hiteshsahu.slicedemo.advance/toggle
-
SLICE WITH RANGE SLIDER & PROGRESS BAR Show how to show progress bar and Slider in Slices & control Media Volume of the device
content://com.hiteshsahu.slicedemo.advance/slider
-
SLICE WITH GRID Show how to show Grid of Images in Slices
content://com.hiteshsahu.slicedemo.advance/grid
-
SLICE WITH WIFI LIST Show how to show List of Wifi along with show more option.
content://com.hiteshsahu.slicedemo.advance/list
-
COMPLEX SLICE: Complex slice with more than one grid and row
content://com.hiteshsahu.slicedemo.advance/combine