arrow
Back to blog

Wear OS Development Tutorial. Part 2

clock

12 min read

Today individuals set high standards for their gadgets. First of all, they expect them to be quality, robust, and multi-functional. Secondly, they want to get a one-stop-shop solution to rely on for performing their everyday actions — a so-called smart assistant always at hand, easy in use, and still very advanced. Fortunately for tech-savvy users, there’s such a device, which can either be stand-alone or extend their mobile’s functionality — namely, a smartwatch.

Smartwatches have become increasingly popular worldwide, and their market position is projected to grow, reaching 81 million unit shipments by 2021. Thus, turnover is expected to increase by more than 50 percent between 2019 and 2022. The previous article in this series was dedicated to the current functional capabilities of smartwatches, the most popular operating systems (OSs), major manufacturers, and compatibility with mobile phones. One of the most promising directions in the field is Android app development, as the smartwatches with Android Wear OS are forecasted to gain the largest market share, outpacing its competitors in less than two years.

Given the popularity and success of Google Wear OS apps, we’ve decided to focus this article on the core aspects of the wearable mobile app development process, discuss nuances that should be addressed carefully, as well as share our best practices on how to submit apps to Google Play Store.

So, let’s start our Wear OS app development tutorial with drawing the line between Android and Wear OS, are there any differences?

Wear OS vs. Android

As we’ve already mentioned in the first article, Wear OS by Google Smartwatch was Android Wear before the rebranding in 2018. In fact, the wear OS platform is based on Android with all its capabilities, restrictions, and nuances. Therefore, if you’re already familiar with Android mobile app development, Wear OS shouldn’t be a problem. It barely differs from a fully-fledged Android system, except for the lack of some packages:

  • android.webkit is an open-source engine for displaying web pages that has turned into a standard for mobile browsers. It was developed from the code of the KHTML and KJS libraries used in the KDE desktop environment.
  • android.print comes with classes for the implementation of printing support in applications. These core classes are also used by other more specialized packages related to printing.
  • android.app.backup includes backup and restore functions. Consequently, apps with backup copying activated can restore the previous user data when reinstalled.
  • android.appwidget provides the components needed to create “application widgets” for users to immediately access app services and data without starting the solution itself.
  • android.hardware.usb enables communication with USB peripheral facilities hooked to Android-based devices.

Android Wear Tutorial: Application Structure

When your work touches on new Android Wear apps development processes, be ready to roll up your sleeves. After studying Android wear programming and learning Android wear tutorials, you’re almost ready to go! Just remember to remain patient and focused on your main goals. Done? Now let’s go ahead.

Regarding Android wear development for a smartwatch, you need to select the “Wear OS” tab, an empty Activity, or any other available, depending on the project considerations or your preferences. Two modules will immediately appear in the package of your application: a wear module for smartwatches and an app module for phones or tablets. If you want to add smartwatch support to the existing project, then you should open it, go to the File -> New -> New Module …, select the “Wear OS Module”, and set it up. Once that is done, a folder with the name of the specified module will appear.

The two modules will be assembled into two different .apk or .aab files. Nevertheless, they must share a package name and be signed with the same certificate when released. This point is critical since applications should be able to interact with each other through Google Services. Although, you still can create a Wear OS app, neglecting a mobile platform.

UI Layout Design

A wide variety of devices — different sizes, forms, and screen resolutions — is one of the major Android app development concerns. Even when it comes to Wear OS, there are various screen shapes that should be taken into account, as they can be round, square, and round with cropped corners.

Android app development software and its OS UI patterns work perfectly with Wear OS as well as other Andriod wear apps. Additionally, you can use the Wear UI Library provided by Google, since it comprises a complete set of elements, needed to meet smartwatch style. Consequently, it simplifies the implementation process and reduces design resources.

To do this, you should include the following dependencies:

implementation 'com.google.android.support:wearable:2.5.0' (the latest version at the moment of writing).

There are two UI elements in the library that we should mention, as they are indispensable for Wear OS development:

  • BoxInsetLayout is an Android FrameLayout that can adapt child elements to a round display. It places them into the rectangular area inscribed in the screen circle.

For square displays, such transformations will be ignored at the system level. Thus, the layout will look approximately the same for all watch screens.

Without BoxInsetLayout

With BoxInsetLayout

  • WearableRecyclerView is a convenient pattern that is actively used in mobile app development, but in this case, it’s specially adapted for the watch. Due to the display rounded corners, the upper and lower Views may be cropped near the edges, so this pattern is applied to fix the issue.

  • EdgeItemsCenteringEnabled is a parameter that allows you to set a curved layout for scrolling lists and enhance the central element, which makes it easier to read a list on a small screen.

    • WearableLinearLayoutManager makes it possible to scroll the list with a mechanical wheel on the watch. Moreover, it brings the elements arranged along the screen edges of to the middle, which is also very convenient when using round interfaces.

Now, the support library for Wear includes more than twenty adaptive Views, which you can read about in the documentation.

Data Synchronization

DataLayer API is responsible for data alignment between all wearables associated with a single Google user account. It selects the most relevant data exchange path — namely bluetooth, network, or wi-fi — and instantiates a stable transmission, ensuring that the message will reach the target device.

DataLayer consists of five core elements:

  • DataItem, a component designed to synchronize small data volumes between devices in the wearable infrastructure. You can work with them through DataClient, whereas synchronization is implemented through Google services. In other words, we have a customized connection between a watch and a phone, established for the first time when using the Wear OS program from the Google Play Market. During the configuration, the watch copies the user’s Google account, and actually, Google services synchronize the data choosing the best and fastest delivery option. In its turn, DataItem consists of three parts:
    1. Payload is a byte array with any kind of data limited to 100kb that allows you to serialize and deserialize your object. Google itself recommends putting there some kind of key-value structure, like Bundle or Map .
    2. Path is a string by which we can identify our DataItem. The DataClient stores all data items in a linear structure, which is not suitable for all cases. If we need to reflect some kind of data hierarchy, we will have to do it ourselves, distinguishing objects by URI.
  • Assets is a separate structure that is not stored in the DataItem itself but can have a link to it. Next, we are going to analyze this example of creating and saving a data item. For this purpose, create a PutDataRequest, pass all the necessary parameters to it, and then transfer it all to the DataClient to the putDataItem () method. For convenience, we use DataMapItem, in which the serialization problem has already been solved. It allows us to work with data as a usual Bundle object where you can save primitives.

Like:

val dataClient = Wearable.getDataClient(context)
val dataRequest = PutDataMapRequest.create("DATA_PATH").apply {
	dataMap.putString("KEY_STRING", "data_string")
	dataMap.putBoolean("KEY_BOOLEAN", true)
	dataMap.putInt("KEY_INT", 1)
}

val putDataRequest = dataRequest.asPutDataRequest()
dataClient.putDataItem(putDataRequest)

The DataItem is stored in the DataClient and can be accessed from all wearable gadgets. Now, we can get a list of all items from DataClient and parse them:

dataClient.dataItems.addOnSuccessListener { dataItems ->
	dataItems.forEach { item ->
		if (item.uri.path == "DATA_PATH") {
			val mapItem = DataMapItem.fromDataItem(item)
			mapItem.dataMap.getString("KEY_STRING")
			mapItem.dataMap.getBoolean("KEY_BOOLEAN")
			mapItem.dataMap.getInt("KEY_INT")
		}
	}
}

Assets are used for sending photos, audios, and other files to smartwatches. They can cope with such a high load, while it may turn out to be excessive for DataItem since it is designed for quick synchronization. The assets synchronization mechanism is aimed at saving files larger than 100kb in the wearable infrastructure and is tightly connected with the DataClient. As mentioned earlier, a data item may have a link to an asset, but the data itself is stored separately. Thus, an item may be saved faster than an asset with the file still continuing to load. You can create an asset using Asset.createFromUri / Asset.createFromBytes / Asset.createFromRef / Asset.createFromFd, and then transfer it to the data item:

val dataClient = Wearable.getDataClient(context)
val dataRequest = PutDataMapRequest.create("DATA_PATH").apply {
	dataMap.putString("KEY_STRING", "data_string")
	dataMap.putBoolean("KEY_BOOLEAN", true)
	dataMap.putInt("KEY_INT", 1)

	// Add the photo file
	val asset = Asset.createFromUri(Uri.parse("PHOTO_PATCH"))
	dataMap.putAsset("KEY_PHOTO", asset)
}

val putDataRequest = dataRequest.asPutDataRequest()
dataClient.putDataItem(putDataRequest)

To load an asset on other device, you need to open an inputStream, get the ByteArray, and present it in the necessary form:

val dataClient = Wearable.getDataClient(context)
	dataClient.dataItems.addOnSuccessListener { dataItems ->
	dataItems.forEach { item ->
		if (item.uri.path == "DATA_PATH") {
			val mapItem = DataMapItem.fromDataItem(item)
			val asset = mapItem.dataMap.getAsset("PHOTO_PATCH")
			mapItem.dataMap.getString("KEY_STRING")
			mapItem.dataMap.getBoolean("KEY_BOOLEAN")
			mapItem.dataMap.getInt("KEY_INT")

			// Save the photo file from Asset
			saveFileFromAsset(asset, "PHOTO_PATCH")
		}
	}
}
private fun saveFileFromAsset(asset: Asset, name: String): String {
	val imageFile = File(context.filesDir, name)
	if (!imageFile.exists()) {
		Tasks.await(dataClient.getFdForAsset(asset)).inputStream.use { inputStream ->
		val bitmap = BitmapFactory.decodeStream(inputStream)
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, imageFile.outputStream())
	}
}
        
	return imageFile.absolutePath
}
  • Messages provide text transmission without synchronization; moreover, you can send a message only to a specific node or set of nodes, which must first be obtained through the CapabilityClient. Unlike messages, all DataLayer components provide data caching.
  • Channels are used to transmit streaming data in real time without caching. Such a tool can be especially useful when we need to send a voice message from the watch to a phone. You can obtain a client for channels through Wearable.getChannelClient () and then open an input or output data stream, with one channel being able to work both ways.
  • Capabilities is a mechanism for identifying devices in the wearable network that is particularly useful when we need to send a message to a specific watch instead of all the devices connected via Bluetooth. The tool is very simple: any network device can find out how many nodes support some sort of function and send a message to one of these nodes with the help of the CapabilityClient. To add it to our Android wear application, we should create a res / values ​​/ wear.xml file and put there a string array, denoting it.

Wear OS Development and Google Play Store Release

We’ve come to the final stage of any wearable app development process — release to app stores and availability for public use. The submission of solutions for Wear OS to Google Play Store is rather straightforward, especially if you’ve already published applications for mobile or tablets. Moreover, you can use your active account with current pricing and distribution settings for adding and publishing new wearable software solutions. So, how to get it right the first time?

Start with reading over the recommendations on specific Android Wear app tutorials, general app development tutorials, and design patterns to make your product not only attractive but also accessible and easy in use. Developing your next wearable app, take into account Google quality criteria, thus preventing costly re-development and missed deadlines. Moreover, don’t miss the key point: Android Wear OS is designed to provide users with the necessary information at the right time. That’s why handy interfaces should start automatically; they are neat and require little to no interaction with the user.

When it comes to app design, we should note that there is a big difference between design for wearables and mobiles or tablets. In the first case, we should factor in various pros and cons of gadgets, use cases, and ergonomic requirements. But despite all the nuances mentioned, wearable technology design is the gist, and it requires thorough planning and testing.

Proceed with defining the objectives and acceptance criteria. Android Wear users should be able to get the important information at the right time. Consequently, your wearable technology software should be optimized for small screens, run automatically, and require minimum intervention from the user. Meanwhile, good solutions not only send standard notifications but also offer a wide range of features and full compatibility with different screens.

On top of this, if you already have a powerful solution for mobile, tablets, and other devices, Google recommends including APK for smartwatches in it, all while using the same package name and description for Google Play Store. Consequently, you’ll keep existing reviews and ratings, while users will be able to update their software seamlessly.

If the APK file meets all the requirements for an Android Wear application and it’s ready for publication, the final step will be to submit the app to Google Play Store. Don’t forget to add screenshots and set up the preferred distribution settings. Before publishing, go to the ‘Pricing & Distribution’ section and specify that your solution is compatible with Android Wear OS.

If your solution complies with the quality standards, it will be verified and listed in the Google Play Store, so users will be able to find and download it to their gadgets easily. Additionally, the product will be added to the Android Wear app category, meaning that it’s compatible with Android Wear OS. Before sending a review request, be sure to add at least one screenshot for Android wearables to not only minimize the likelihood of being rejected but also to attract more users after the publication.

As soon as you send the request and save the changes, you can publish the app, following the same procedure as for mobiles and tablets. Eventually, the Google Play Store team will check it and notify you about the results.

Keep in mind that the fact of review doesn’t entail the online visibility of the solution. It should be published to become available for download in the Google Play Store.

Now let’s move to the actual review process. You can check the status of your Wear OS app anytime, as it’s visible in the ‘Pricing & Distribution’ section of the Google Play Console. There you’ll see one of the following states:

  • Pending — the verification of the solution isn’t complete yet;
  • Approved — the app is reviewed and approved. It’ll soon become available for users;
  • Rejected — the application was checked and denied. You can find out about the refusal causes from the letter that was sent to your email address (associated with the Google Play Console account). As soon as you make all the necessary changes, you can re-submit the application to Google Play Store.

We’d like to conclude with a brief checklist for app development teams and business owners ready to go public:

  1. Make sure that your Google wear app(s) meets the Design for Wear OS guidelines;
  2. Provide all the necessary information to Google Play Store and be sure to attach at least one screenshot;
  3. Select the right application file in the ‘All Applications’ page;
  4. Find the ‘Wear OS by Google’ category in the ‘Pricing & Distribution’ section;
  5. Click the ‘Distribute your app on Wear OS by Google’ checkbox;
  6. Submit the updates by clicking the ‘Save’ button.

Conclusion

In this article, we’ve covered the essential aspects of wearable technology development and design, as they may prove useful to not only software engineers but also for project managers and even business owners who wish to understand their product development teams better. Our experience shows that building smartwatch Android apps doesn’t differ much from software development for mobile devices, except for design, and in this case, it’s critical to follow the guidelines.

Meanwhile, the battle for customers’ wrists is getting even more exciting and furious. Gadget designs become more sophisticated, all while Wear OS products become even more functional, powerful, and engaging. No matter if you want to stay posted with quick notifications, take notes, listen to music offline, control your heart rate, count steps, follow a healthy lifestyle, wearables get you covered.

If you want to join the battle, but don’t feel confident about your idea, strategy, or tech stack, try learning more from any credible Android wear tutorial. Having done that, you can always contact our team. Dashdevs is a reputed mobile and wearable app development company with a proven track record, streamlined operations, and extensive knowledge in the field. We partner with industry leaders to not only provide technical solutions but also to resolve customers’ top-of-mind problems, bring in innovation, and shake up the market.

Share article

Table of contents