STRV's Take on Android 11
A brand new release of Android is here! We’ve been testing the functionality ever since the beta release and can’t wait to share our experience with you. This article is just a brief summary of the latest features; if you want to share your thoughts or experience with us, tag us on Twitter with #strvandroid. Can’t wait to hear from you!
PEOPLE & IDENTITY
Android 11 brings a new Conversations section into your notifications center. You can start a new conversation directly from the notification and use Conversation Bubbles to quickly get back to a conversation.
Here’s how you can implement a Conversation Shortcut:
val person = Person.Builder() .setName(...) .setIcon(personIcon) .build() val shortcut = ShortcutInfo.Builder(context, convesationShortcutId) .setLongLived(true) .setIntent(...) .setShortLabel(...) .setIcon(personIcon) .setPerson(person) .setCategories(...) //to enable sharing ... .build() context.getSystemService(Context.SHORTCUT_SERVICE) .pushDynamicShortcut(shortcut)
With a properly implemented shortcut, you ensure your conversation notifications are put to the top of the list in the notification panel. You can add priority to the conversations and can turn these conversations into bubbles and pin them onto your launcher screen. You should only use shortcuts for real-people conversations, not for bots and one-time notifications. The system limits shortcuts to 10 at a time but, when using the pushDynamicShortcut as seen above, the system handles this limit automatically.
To publish your Conversation Shortcut to the notifications bar, simply do the following:
val notification = Notification.Builder(context, conversationChannelId) .setStyle(Notification.MessagingStyle.Builder(person)) .addMessage(...) ... .build()) .setShortcutId(conversationShortcutId) ... .build()
Your existing notifications will still be visible in the Conversations section, but users won’t be able to put them in a bubble or mark them as a priority until you provide them with a Conversation Shortcut. To find out more about how the notifications are ranked and to get further info, check out this article: People Notifications
Bubbles enable quick transitions to the conversation, as known from apps such as Facebook Messenger. To learn how to implement Bubbles, follow this Bubbles Codelab
Since there are many ways to sign in to your favorite applications, logging in to your account after a while of not using an app can be quite challenging. Users might forget the sign-in method they used, the email they used to sign up or, very often, the password. To make the process easier, Google presented One-tap sign in and Block Store as a part of its new Google Identity Services Library.
One Tap is a new cross-platform sign-in mechanism that supports multiple types of credentials. When using one tap, users get a token-based, passwordless account associated with their Google account. You can find more information about One Tap here: One Tap, or in this article: One Tap Medium.
Block Store is a token-based sign-in mechanism built on top of the Backup & Restore feature. After logging into your account, you can choose to store your auth token to the Block Store. The token is then stored locally on the device, end-to-end encrypted and stored in the cloud. This feature is very useful when, for example, a user gets a new device and needs to sign in to multiple apps. When the user restores the device either via device-device or cloud restore flow, tokens stored in the Block Store are automatically retrieved as well.
ML Kit has been Google’s recommendation for on-device machine learning for a while now. That’s why a lot of work is being done to make it more performant and easy to use.
One of the steps taken in this direction is that the ML Kit has become a standalone SDK and no longer requires developers to have a Firebase account. Adding ML Kit functionality into an application is as easy as adding a gradle dependency:
Apart from being easier to use, ML Kit can now be shipped through Google Play Services, which means that the model can be reused between apps and doesn't have a large impact on the application’s size footprint:
Please note that this is currently supported only for selected features: Barcode Scanning, Text Recognition and Face Detection.
ML Model Binding
Developers who have worked with custom models and ML Kit know that it can be quite challenging. That is why Android Studio 4.1 comes with a new tool called ML Model Binding.
This tool helps you integrate custom models into your Android more easily. It lets you import any TFLite model, and Android Studio generates classes for you so you can run your model with type safety and without the need to convert your input and outputs into ByteArrays.
The plugin currently supports image classification and style transfer models, provided they are enhanced with metadata.
PRIVACY & SECURITY
Previous Android updates were mostly incremental and they mainly brought improvements in terms of security and privacy features. This year is no different; security is something Android really needs to catch up on when compared to Apple’s approach baked in the iOS ecosystem, so it is great to see this gap getting more narrow this year. Let’s see what privacy features were in Google’s oven in the last twelve months.
Permissions is one of the parts of the Android OS which are revamped almost every year. And we like it! This time, we got several improvements for Permissions. Users can now grant single time permissions. As simple as that. It may be handy to use if you do not trust some app that much, or you only use it sporadically. Also, if you do not use a certain app for a few months, Android will revoke all permissions for your peace of mind. And background location permission is one more novelty to care about. Users are now asked to grant location permission one more time, just to allow the app to obtain it in the background.
Scoped Storage Changes
Storage in Android 11 underwent many small changes, which add up to a decent revamp. Developers need to account for even bigger limitations than before, which can give them a headache but, ultimately, this data sandboxing shields users from malicious apps and privacy concerns. This means no access to app-specific folders of other apps, even if they explicitly allowed it. The system also forbids actions like ACTION_OPEN_DOCUMENT or ACTION_OPEN_DOCUMENT_TREE in locations android/data/, android/obb/, root directories of any storage and Downloads folder. These limitations have to be counterbalanced with some new goodies. Developers can now opt-in to access files by raw paths or take advantage of batch edit operations for media files.
You cannot avoid scoped storage if you decide to target Android 11 (API 30) in your app, but you can still opt out by setting requestLegacyExternalStorage to true in manifest if you target Android 10 or lower. This is an option that will eventually be ruled out by increasing requirements for the minimum target level in the Google Play store, so it is better to try to adhere to these new rules now.
Electronic IDs Support
Driving license or state ID in your Android phone, how cool is that! Google did some necessary tweaks and additions to make it happen. But it will not be ready just yet; we still need to wait for ISO's official guidelines to have everything standardized. There could be some new requirements for hardware, which would allow ID information to be read even when a phone is turned off. Maybe in a year or so, you may finally be ready to ditch your wallet for good!
Faster Security Updates Through Google Play Store Modules
This is yet another extension of Project Mainline, the goal of which is to modularize parts of Android OS to make it updatable from the Google Play store, just like an app. It attempts to solve the daunting issue of slow security updates which can take forever even for critical security issues (hello, Samsung). We hope that this will get continuous focus from Google because slow updates have been one of the worst security issues on Android for years.
Google redefined standards for authentication levels and cleared up which methods will be available for which purposes. Some weak face unlock methods based only on using the front camera—with no additional sensors—could not be used for payments and other highly secured applications. Now, there are three levels of authentication method security. The most secure one will allow all operations, such as work with Keystore. This method could be a password, for example. The second level is the ability to authenticate identity on the app-level, with features like high precision fingerprint read. The least secure level is just for unlocking the screen and it can be done by low-level security features, like smart lock. All new changes are nicely summarized in this blog post.
Compatibility is a hot topic every year, with each new API update. Google is contiuously trying to make upgrades easier for developers. Developers Preview and the Beta version of Android 11 are available a couple of months before the public release, giving them enough time to test their apps. Developers need to make sure that their apps can run on the latest Android version without any issues.
There are two types of compatibility changes. The first group affects all apps on Android 11. This group includes features like one-time permissions or permission dialog visibility. You can find all of them in the documentation. Developers need to install and run the app on devices running Android 11. They should focus their testing on these changes. If they find any issue, they should fix it as soon as possible.
The second group affects only apps targeting API 30. It is necessary to check if they are asking for background location only if they have already granted permission for a foreground location. This permission cannot be enabled directly from the app; it’s only possible from settings, where they can redirect the user. That is only one example of targeted change. Follow the link to see other changes. Until Android 10, it was possible to test these changes only when the targetSdkVersion was updated into the necessary version. This has improved with the Android 11 App Compatibility Framework.
App Compatibility Framework
A compatibility framework is a new tool introduced in Android 11 to test behavior changes without targeting the latest API. Follow this link and find a list of all toggleable changes. These changes can be enabled or disabled either via ADB or from the developer's options. It allows developers to test targeted changes separately. It is only available for debuggable apps. It’s best to enable only one feature at a time to easier identify the source of possible issues.
Parallel Instrumentation Tests
Android Studio 4.2 brings parallel instrumentation tests on multiple virtual or physical devices simultaneously across different API levels. This feature helps developers to run tests on several devices at once and have all results in one place. Developers should choose them according to their device statistics in the Google Play Console. It’s recommended to have one device with minSdkVersion, the other with targetSdkVersion and another with the latest available API version.
As is custom for Google, with every new version of Android OS and Android Studio, the development process gets a little bit easier and more efficient. Let's take a look at the most interesting new features and improvements for developer tools.
Forget the times of constantly switching application windows. With Android Studio 4.1, we have an emulator embedded in IDE which makes it more available for running and testing our apps, plus it saves precious on-screen space. You can easily assign a keyboard shortcut to hide and show it. If you haven't yet, start using snapshots to make the emulator boot even faster. Just hit the save snapshot button when you have it in the state you like. And on the next emulator start, you will begin right there. Everything's available from the emulator options panel.
Parallel Device Testing
If you’ve ever run instrumental tests, you know it can take quite a long time to finish. The new version of Android Studio has you covered with parallel device testing. In the device menu, you can select the Modify Device Set option and choose several devices from those recognized by the studio (both physical and emulated ones). Once the app is built, it will be pushed into all selected devices, and the test starts running upon finishing the installation process. You will see the results for each device in the matrix and can easily examine failures separately.
Layout Inspector & Layout Editor
The new version of Android also brings some news for visual design tools. The Layout Inspector enables you to pull down the whole view hierarchy for deeper examination. While running the app on emulator view, the hierarchy will be updated live.
The coolest part of the Layout Inspector is the 3D view feature, which helps you see exactly how the view is created. Perhaps you can identify views that are completely hidden and should be removed, or you notice over-drawn elements. It can even tell you that something looks different because it found a better match in the style lookup priority order.
There's something new in the Layout Editor as well. The newly-added wrench tool icon in the top right corner of your layout can temporarily turn off all the tools’ attributes, which will reveal the content below. The layout component tree now has a second column with the ability to hide and show views conveniently—directly from the outline.
Our favorite for the Layout Editor is the new Transform panel, which makes it easier to visualize how the views are transformed. Last but not least, the support for accessibility validation was added (though this feature is still in development).
Dagger & Hilt Navigation Support
Everyone who ever used Dagger or Hilt knows how easy it is to get lost in generated code for dependency injection. The latest version of Android Studio 4.1 brings new gutter icons that allow you to easily navigate between Dagger-related code.
The icon with the arrow pointing up will show you where the dependency is coming from. The second icon shows the places where the type is used as a dependency.
Jetpack Compose Support
Jetpack Compose has recently been growing in popularity amongst many developers. Even though it's not fully ready for production use yet, recent versions of Android Studio make using Jetpack Compose easier than ever. Composable functions can be annotated with @Preview annotation, which shows a preview to visually tweak your composables. The main benefit of preview is that it is faster than running the app, and it allows you to display multiple composables at the same time and test them under different conditions. Preview also allows us to navigate within the composable code just by clicking or double-clicking on a selected element.
The @Preview annotation can be repeated multiple times to override various aspects of the appearance, like large displays, different fonts or even different themes than the default one.
Using @Preview enables automatic creation of the documentation on how to use composables. You can simply add a documentation tag (@sample) pointing to a fully referenced preview and the result is very surprising.
Note: This is not a complete list of news in Developer tools. There have also been certain refinements in the Systrace profiler and Database inspector that are worth checking out.
Android TV is experiencing a huge boom these days mainly because of how many people are unfortunately being quarantined and are therefore searching for new ways to work out, learn and have fun. It’s also thanks to many new entertaining apps being shipped out to the world by developers. Currently, there are more than 7k apps and games for Android TV in the Google Play Store, which makes it a very interesting platform as the apps can capture attention among the small competition. Google has also put some effort in making TV support easier for developers, so let’s take a look at what’s new and how you can improve your current apps so your users can enjoy them to the max.
Google Play Store
Google Play Store received a major update, helping it to become much more synoptic, easy to control and search in. As a part of this update, Google Play Store was also made available on emulators; you can now install apps on your emulator device directly, without any need to sideload the apps.
Instant apps are now supported on Android TV. After logging into the Play Store, you now have the option to try apps before installing them. For those who are not familiar with this feature yet, it enables the user to run the app without the need to install it directly from the Play Store. This has proven to be very helpful for users especially with games, which often take up a lot of storage space on the device—making it harder for users to commit to installing them. You can find more about the instant apps here: Overview of Google Play Instant. To get started with Instant apps for your product, follow this link: Create an instant-enabled app bundle.
Android TV Assistant also received a couple of interesting updates, led by the new and improved playback support for media. You can now say Play <movie> on <app> and the desired content will start playing on your TV using the app you requested. The results you receive while performing searches via your Google Assistant are now also personalized.
Cast Connect is one of the most exciting features on Android TV. With Cast Connect, you can send the content to your Android TV from your phone and enjoy the native experience of the app, including controlling playback with a remote controller. There’s no need to use your phone to control the playback anymore. To learn how to include Cast Connect in your apps, follow this link: Cast Connect Codelab.
Google also introduced the Frictionless Subscription feature for Android TV. From now on, you can choose the option to Subscribe & Install from the app’s Play Store screen. After tapping this button, you’re taken to the subscription selection screen (without the app being installed yet). After you select your preferred subscription model, a silent sign-in to your Google account is performed which then triggers the new account creation on your backend with Google credentials. As soon as you receive the confirmation of the successful account creation, you’re taken to the app and are signed in automatically with your new account. This feature can save you a lot of typing on the Android TV remote, which can be quite unpleasant.
Leanback Library is a framework that makes building an Android TV experience much easier by providing ready-made widgets and navigation components for the best possible user experience. If you want to get started with Android TV development, you can use code from our Android TV Workshop here: STRV Android TV Workshop.
In the Android 11 update, Google introduced Paging support, which means you’ll be able to use the Paging 3 library for TV apps the same way you can on mobile. If you want to find out more, please follow this link: Paging 3 Library Overview.
The next addition to the Leanback Library is the support of the Top Tab Navigation. Google introduced two new components: LeanbackTabLayout and LeanbackViewPager. You can use them in your apps like this:
val leanbackTabLayout = findViewById<LeanbackTabLayout>(R.id.tab_layout) val leanbackViewPager = findViewById<LeanbackViewPager>(R.id.view_pager) leanbackViewPager.setAdapter(adapter) leanbackTabLayout.setupWithViewPager(leabackViewPager)
Google also introduced the AppCompatActivity as a part of the Leanback. Previously, developers had to use FragmentActivity in their Android TV code, which then forced them to split their codebase. This isn’t the case anymore; Android TV developers are one step closer to the single codebase for all platforms.
Jetpack Compose is a declarative UI Toolkit for Android written in Kotlin. Along with the Android 11 release, Jetpack Compose was promoted from the development stage to alpha; most of the API should be final, but there could still be some changes in the future. We think that it's not ready for production apps yet, mainly because of possible API changes.
Compose uses Composable functions instead of Widgets, which we are used to using nowadays. Composable functions have to be annotated with @Composable. Composable functions might get called by the system multiple times, so keep that in mind. The process is called Recomposition. Because of this, it's better to have Composable functions stateless. If you introduce some state in a Composable function, it might break your UI. Imagine that you generate random color for your text in the Composable function. The text color would be changed to a different one each time a Composable function gets invoked by the system or your code. To fix this, Compose has a way to remember the state during recomposition, so you can have stateful Composable functions. Most built-in Composable functions are stateless.
Compose is really capable and has alternative Composable functions to most Widgets. We've already built a sample Weather Application using only Compose, and it was really fun. You really have to switch your mindset about the UI structure. You should also prepare to spend a lot of time searching for suitable Composable functions to replace the desired Widget. Think of it like switching from Java to Kotlin, because it's a similar process. It seems really different at first sight, but after a few hours of playing with it, you realize it's better and faster; you end up writing only Kotlin and don't have to switch between Kotlin code and XML layout all the time.
We are looking for beta and stable releases, so we can consider using Compose in production apps.
That’s all from the STRV Android team. If you have any questions or want to discuss the above, let us know!