Check Whether the App Is Running as an Instant App
One more useful thing to know is if your app is currently running as instant app. This feature lets you disable functionality that won’t work due to instant app limitations.
To perform the check, you use the following InstantApps API:
InstantApps.getPackageManagerCompat(this).isInstantApp
Open MainActivity.kt again and replace lines 70 and 71 with:
if(!InstantApps.getPackageManagerCompat(this).isInstantApp) {
tvNoon.text = formatTimeString(this, R.string.noon_format, sunTimetable?.noon)
tvDayLength.text = formatTimeString(this, R.string.day_length, sunTimetable?.dayLength)
}
This will fill the TextViews for noon and day length only if the app is running as installed app.
Go to LocationDetailsActivity.kt and replace lines 63 and 64 with:
if(!InstantApps.getPackageManagerCompat(this).isInstantApp) {
tvNoon.text = formatTimeString(this, R.string.noon_format, sunTimetable?.noon)
tvDayLength.text = formatTimeString(this, R.string.day_length, sunTimetable?.dayLength)
}
This does the same for the activity that displays data for a location searched for on MainActivity
.
Now build and run the app as an instant app again.
You can see that the information about noon time and day length is no longer displayed either on the main screen or when you search for a location:
Now run the installed app:
In the installed version, you can see all of the information and you won’t get the install prompt.
Where to Go From Here?
That’s it! You’ve made your very first instant app! :]
Now that you know how to add instant functionality to your apps, make sure you check out the official UX best practices.
For step by step details on publishing Instant apps, check out Google Play Console help.
For more details on related topics not covered here, visit the official documentation on getting started with Instant Apps and check out how to add instant functionality to Android games.
I hope you have enjoyed this introduction to Instant Apps. If you have any comments or questions, please join the forum discussion below!