This code sample shows how you can leverage Play Feature Delivery to enable on-demand delivery of the Amazon IVS Player SDK, which will be downloaded from the Google Play Store when requested.
A modularized app will create clearly defined boundaries between separate parts of your application, and allowing you to decrease your app’s size further. In practice, this means that you can call an API to install the module (the Amazon IVS Player SDK) after the app has been downloaded and installed on your user’s device. Using on-demand installation saves initial download time and size.
This is achieved by releasing your Android application with .aar bundles. (Note: this cannot be done with an .apk
)
The setup is tailored for a project that uses the nav-graph navigation. Follow along for instructions. If needed, please refer to the Quick Start Guide provided by Google.
Click on File -> New -> New Module...
Select Dynamic Feature and enter all the values necessary.
Pick the desired feature type - in our case we use on-demand delivery.
The class must extend SplitCompatApplication
- don't forget to add it as name
in your application
tag in theAndroidManifest.xml
file.
Override the attachBaseContext(..)
function of the application and call SplitCompat.install(this)
.
If you wish to use the feature module after it's downloaded you must call SplitCompat.installActivity(this)
in every activity that needs access to it. If you plan to use the module in an fragment, you must install it in the parent activity of the fragment.
Add the following:
api "androidx.navigation:navigation-dynamic-features-fragment:2.3.5"
implementation "com.google.android.play:core:1.10.0"
to your main gradle file to enable feature module loading when using the navigate(..)
function to switch between fragments.
In your activity layout file change the navigation host name
to:
android:name="androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment"
There are two ways to handle the feature download, either use the InstallManager
to observe the feature download or create a fragment that extends the AbstractProgressFragment
and implement the 3 callbacks to listener for the download state.
Both appoaches have known issues:
- The manual install way described here has a bug with the
installMonitor.isInstallRequired
boolean. It will always returntrue
even if you have thefeature
installed. This means that when you use thenavigate(id, null, null, DynamicExtras(installMonitor)
as described there and then use it again when theinstallation
is completed - you'll have your fragment opened twice. - The custom progress fragment has a bug with the
onProgress
callback - it doesn't return values smoothly, so it'll jump from 1%-2% to 100%.
The demo app in this repository uses the custom progress fragment. The fragment is launched automatically when navigating to a fragment that is inside a feature module.
To enable the progress fragment - set it as value in your nav_graph
like so:
app:progressDestination="@id/loading_fragment"
When using the custom progress fragment you don't have to worry about download / install states as it will be handled automatically. If the fragment is loaded or already pre-loaded, it will be opened.
To test how the feature delivery works either upload your app to the Google Play Store, or use the bundletool to simulate the experience.
amazon-ivs-on-demand-android-demo.mp4
- Amazon IVS Amazon Interactive Video Service is a managed live streaming solution that is quick and easy to set up, and ideal for creating interactive video experiences. Simply send your live streams to Amazon IVS and the service does everything you need to make ultra-low latency live video available to any viewer around the world, letting you focus on building interactive experiences alongside the live video. Learn more.
- Amazon IVS Player SDK for Android
- Amazon IVS docs
- User Guide
- API Reference
- Learn more about Amazon IVS on IVS.rocks
- View more demos like this
This sample code is made available under a modified MIT license. See the LICENSE file.