Welcome to Innominds Blog
Enjoy our insights and engage with us!

Six Easy Steps to Create Android Instant Apps

By Karthik V Pedamallu,

Ever wondered about how to try out an app without installing it ? We wrote about App Clips in iOS in our last blog. Here we will show you how to create instant Apps on Android OS.

Screenshots and video listed on the Playstore are not always enough for a user to have complete experience of the app. Did you face a situation where you want to use the app one single time and be done with it? This is exactly what the "Google Android Instant App" offers.

Instant apps runs just like other local apps, but they are native containers with access to a device's hardware. It does not take up storage on the device, because end users do not have to install them.

Google Play Instant empowers your apps to dispatch on devices running Android 5.0 (API level 21) or higher. Unlike other apps, Google Play instant apps have an option called "tap to try" an app or a game, prior to app installation. This gives a better user engagement with great mobile app experiences, even though you do not have the application installed on your device.

Instant apps provide an easy way to use apps directly from anywhere including search results, social media shares, messages, beacons, NFC and other applications or even other instant Apps because these are triggered by URL intents which allows them to start from anywhere.

Use cases for instant apps

With instant apps offering a completely native experience without the need to install the app, there are many use cases developers can offer as options to the existing applications as well.

  • Car parking solution
  • Restaurant menu display
  • Shop and checkout at both virtual and physical stores
  • Demo stage of a game
  • One time authenticators
  • Demo of a video or image analytics app
  • Simple routing information for a location

All of the instant app use cases are driven by the need, usability, and discoverability of the application. The simpler the use case, the popular and more useful it becomes.

Where to find instant apps

To access an instant app, Android users must first opt into Instant apps by selecting 'Settings' -> 'Google' -> 'On' under the Instant app feature.

image1

There are things instant apps can't do

Such as:

  • Accessing the device identifiers like IMEI and MAC addresses
  • Use background services in the device
  • Performing background notifications
  • Accessing the device’s external storage
  • Getting access to the list of apps that are installed on the user’s device unless those applications made themselves discoverable to Instant apps.

How to build an instant app

There are two approaches to create instant apps

  1. With App Bundles (recommended one)
  2. With feature plugins (deprecated)

If you have an existing instant app project that uses the deprecated plugin com.android.feature, migrate your instant app by following the steps in https://developer.android.com/topic/google-play-instant/feature-module-migration

Instant app with app bundles

An app bundle combines all of your code into a single format that can be uploaded to Google Play Console and helps in optimizing the kind of APK delivered to the device based on device requirements. Consider an app bundle as a big file containing code for all the architectures and variations of devices and Google Play Console helps in delivering the right artifacts to your device based on your device configuration. You can get more information about app bundles at https://developer.android.com/guide/app-bundle

Identify the use case: If your current solution does not offer a single time use type of use-case, it does not make sense to go ahead with instant app. The first problem to solve is whether your current solution has this type of use-case. For example, a social networking app need not make an instant app for posting a single post. This is a non-productive example of instant app usages.

Build and distribute the app: Once the use case is identified, the next process is to build and make it available in the play store.

Make the app discoverable: Once uploaded to the app store, the next step is to make sure that it is discoverable by the user. This can be done via a specific URL for the instant app. The other means include having a set of QR codes at the target location or advertise the same using website banners on your website as well. These are small steps that will go a long way in making your app discoverable.

Step 1 - Start building the project

To construct an app that supports Google Play Instant, you need to install the instant app SDK. Go to Studio > SDK Manager > click on SDK tools > and then install Google Play Instant Development SDK by checking the box and click ‘Apply’

image2

Step 2 - Create flavor

Because an instant app size is restricted to 10MB, creation of flavors is a must. If your main app is < 10MB you need not create the flavor (you can directly go to Step 3). Create a flavor in app Gradle with installed and instant names like below

flavorDimensions "InstantExperience"
productFlavors {
instant {
versionCode 1
versionName "1.0"
}
installed {
versionCode 2
versionName "2.0"
}
}

Step 3 - Create manifest

Create a manifest under instant flavor rather than the main folder with below additions of sandbox version and dist:module.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" package="com.inno.myfirstinstantapp" android:targetSandboxVersion="2">

<dist:module dist:instant="true">

</dist:module>

Step 4 - Build the interface and interaction

Build your interface and interaction within the instant app in this instant flavor keeping in mind the restriction of size and supported permissions.

Step 5 - Testing instant apps

Testing an instant app is not easy. First create app bundle for instant flavor (Build > Build Bundle(s) / APK(s) > Build Bundle(s)). And download the latest buildtool jar from the https://github.com/google/bundletool/releases 

Go to the downloaded file folder in command prompt and run the below command:

bundletool-all-*.jar build-apks --bundle=instant-app.aab --output=my-app.apks

The above one extracts .apks file in the destination folder from .aab file.
Next, Go to $sdkFolder\extras\google\instantapps\ and run the below command

ia run my-app.apks

Now it installs in the connected device with charge(🗲) symbol on the app icon.

If you want to use the main folder code, you can identify it as the main app or an instant app with a simple condition. For this, you have to include the below dependency in app build.gradle file.

implementation 'com.google.android.gms:play-services-instantapps:*'

if(InstantApps.getPackageManagerCompat(this).isInstantApp) {

// Code here if anything want to do only in instant app.

}

If you want to tell the user to install the full app while using an instant app, use showInstallPrompt API which allows you to prompt installation when users decide to install your app or game.

public static boolean showInstallPrompt (Activity activity, Intent postInstallIntent, int requestCode, String referrer)

activity The activity launching the dialog
postInstallIntent The intent to launch after the instant app has been installed. If postInstallIntent is not provided or invalid, it falls back to the default launcher activity.
requestCode The request code to pass to startActivityForResult(Intent, int)
referrer The install referrer string

 

Returns

  • if the install prompt is successfully displayed.

Step 6 - Build app links for integration on your site

The next thing after building your instant app is to make sure it is easily discoverable. This is where App links become helpful. They allow website URLs to open your instant app without going to Playstore. To achieve this, the activity should be visible and browsable. Add the following settings to your activity.

<intent-filter android:autoVerify="true">

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />

<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="http" android:host="example.com" android:pathPrefix="/main" />

<data android:scheme="https" />

You can test this link by simply accessing the mentioned URL in a browser after installing the instant app with above mentioned tool in the device. And from the link you can pass the data to an activity.

With the below code in instant activity, you can receive values from the URL.

if (intent.data != null) {

println("Name = " + intent.data?.getQueryParameter("name"))

println("Platform = " + intent.data?.getQueryParameter("platform"))

}

Publishing an instant app

Select your app in Play Console and navigate to setup in left menu > advanced settings. Click on “release types” tab and make sure you have “Google Play Instant” selected and it’s active. If not, click “Add release type”, select it from the list and activate it.

image3

And then, go to Production on left side menu or if you would like to test before production, go to Testing -> Open/closed/Internal menu and select instant apps only as shown in below screenshot. Under “Active tracks” click on “Manage track” and then “Create new release”.

image4

Now you can upload your instant app aab/apk file. If your instant app is bundled with your main installable app you could simply select the aab file that you uploaded earlier from the library.

Conclusion

Instant apps are one of the best ways to attract or engage a potential user. The future of demo or trial versions is through the instant apps experience. Google promotes the inclusion of instant apps experience with the new .aab format and is also gearing up to give out multiple instant app experiences for a single app in the future.

We at Innominds have the experience and the expertise to guide your business towards this unique experience to improve user engagement and interest.

Topics: Six Easy Steps to Create Android Instant Apps

Karthik V Pedamallu

Karthik V Pedamallu

Karthik V Pedamallu - Team Lead - Software Engineering

Subscribe to Email Updates

Authors

Show More

Recent Posts