Adapt Android application for Wear OS

In March 2018 Google made Android Wear platform re-branding. New name – Wear OS. According to statistics, currently in the world of smart watches the leader is the Apple’s watchOS, taking 16,2 %, whereas Wear OS has 7%. However, the smart watch market is still new and we definitely can expect the number of users to growth. This means, we may create apps and watchfaces for wearable gadgets.
Let’s create Wear OS module for an existing Android app. I have just the right one – same old Workout Stopwatch.

 

Create module

Create new module in android studio project and choose wearable app

In build.gradle of created module add wearable dependecies:

dependencies {
    implementation 'com.android.support:wear:27.1.1'
    implementation 'com.google.android.support:wearable:2.3.0'
    compileOnly 'com.google.android.wearable:wearable:2.3.0'
}

Wearable app may be in three states:

  • Completely independent of a phone app
  • Semi-independent (a phone app is not required and would provide only optional features)
  • Dependent on a phone app

For the first two, for independent ones, in Android Manifest add following for <application ../> tag:

 <meta-data
 android:name="com.google.android.wearable.standalone"
 android:value="true" />

otherwise, the application will not be available to users with iPhone.
That is, if this flag is false, then the application can be installed only on the device connected to the phone on which the Play Store is installed.

In addition, for the wear-module, you must add In AndroidManifest.xml <uses-feature> with the value:

<manifest>
...
 <uses-feature android:name="android.hardware.type.watch" />
...
</manifest>


Packaging

Previously, apk for Wear 1.0 were embedded phone APKs. Wear OS allows us separate apk compiled for Wear 1.0 and upload it directly into Play Store. This helps to decrease phone apk size and gives flexibility in app versioning and distribution. “When you upload a watch APK via the Play Console, you can update your Wear APK independently from the phone APK, and users receive updates via the watch Play Store”  more…

Our app will be independent apk, but this doesn’t mean that we cannot use existing code again. Just extract common logic into a library module, and import it into app and wear. Thus, in app and wear modules, only the UI part of the application remains basically.

 

UI

To create beautiful responsive applications in wear os there are new UI-elements . For example, BoxInsetLayout – automatically adapting to round and rectangular screens layout.

BoxInsetLayout      BoxInsetLayout

To create lists for wearable devices there is a RecyclerView analog – WearableRecyclerView

WearableRecyclerView

 

 

Summary

We created wearable module in our project and adapted existing application for Wear OS. Remember that because of hardware limitations watches are not designed for complex applications. They are ideal for notifications, quick messages, or simple applications. Keep this in mind, and publish new applications or Wear OS versions of existing apps on Google Play!

That’s all for today!




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *