By building an app for Fire tablets, you can connect with customers around the world, and grow your revenue . This article explains how you can build your first app for that can run seamlessly across the entire Fire tablet family of devices. The tutorial below draws on a to design and implement layouts that adjust themselves to render content differently across a variety of sizes.
The example below features a single code base that can be used on Android and the Amazon Appstore. A bonus: the example also features one of my two awesome pugs Katsu (wearing a red harness in the picture below!)
. 🐱🐶 Needless to say, if you don’t have a pet, any photo will do.
Without further ado, let’s get started with the three simple pointers needed to build your Amazon Appstore app.
Check for Google Play Service
In MainActivity.kt file, there is a check if the app is using Google Play Service. This is one of the two checks to verify whether the app supports Google Play Service and/or Amazon Appstore.
By using GoogleApiAvailability class, we create a new private function called isGooglePlayServicesAvailable to verify if Google Play Services are available.
private fun isGooglePlayServicesAvailable(): Boolean {
val googleApiAvailability: GoogleApiAvailability = GoogleApiAvailability.getInstance()
val status: Int = googleApiAvailability.isGooglePlayServicesAvailable(this@MainActivity)
return status == ConnectionResult.SUCCESS
}
Check for Amazon Appstore
We also implemented a check to verify if the app is installed from Amazon Appstore.
If the installer package name is equal to com.amazon.veneziathen it is indeed installed from Amazon Appstore! Just like we did with Google Play Service, let’s create a private function called isInstalledFrom AmazonAppstore.
private fun isInstalledFromAmazonAppstore(): Boolean {
val installerPackageName = getInstallerPackageName()
return installerPackageName == getString(R.string.amazon_appstore_identifier)
}
Display your pet photos
Now for the fun part! You might be wondering where what the purpose of your optional pet photos were. Now is the time 🐶
To sprinkle some fuzziness into this app, we will be using two different photos.
- Use one of your photo to display if the Google Play Service is available
- Use provided for supported file types. Add the code snippet below back in the
MainActivity.ktfile.
CODE@Composable
fun IdentifierImage(
isGooglePlayServicesAvailable: Boolean,
installedFromAmazonAppstore: Boolean,
modifier: Modifier
) {
if (isGooglePlayServicesAvailable) {
Image(
painter = painterResource(id = R.drawable.younger_katsu_in_chair),
contentDescription = stringResource(id = R.string.android_content_description),
modifier = modifier
)
} else {
if (installedFromAmazonAppstore) {
Image(
painter = painterResource(id = R.drawable.appstore_logo),
contentDescription = stringResource(id = R.string.fos_content_description),
modifier = modifier
)
} else {
Image(
painter = painterResource(id = R.drawable.older_katsu_in_chair),
contentDescription = stringResource(id = R.string.other_content_description),
modifier = modifier
)
}
}
}
Determine device orientation
The fun doesn’t end there. Remember how I mentioned about the importance of tablet orientation earlier? This section talks through also code snippet to add a text that will have a different string depending on the window width (landscape vs portrait.)
In order to determine the device orientation, we will be utilizing for building next-level Fire TV tablets, and growing your business on the Amazon Appstore.
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
SOCIAL SHARE CARD GENERATOR