Posted by Garan Jenkin – Developer Relations Engineer
A number of months in the past we relaunched Androidify as an app for producing personalised Android bots. Androidify transforms your selfie photograph right into a playful Android bot utilizing Gemini and Imagen.
Nevertheless, on condition that Android spans a number of type elements, together with our most up-to-date addition, XR, we thought, how might we convey the enjoyable of Androidify to Put on OS?
An Androidify watch face
As Androidify bots are highly-personalized, the pure place to showcase them is the watch face. Not solely is it probably the most often seen floor but additionally probably the most private floor, permitting you to signify who you might be.
Androidify now has the power to generate a watch face dynamically inside the telephone app after which ship it to your watch, the place it’ll robotically be set as your watch face. All of this occurs inside seconds!
Excessive-level design
With a purpose to obtain the end-to-end expertise, numerous applied sciences must be mixed collectively, as proven on this high-level design diagram.
To start with, the person’s avatar is mixed with a pre-existing Watch Face Format template, which is then packaged into an APK. That is validated – for causes which might be defined! – and despatched to the watch.
On being acquired by the watch, the brand new Watch Face Push API – a part of Put on OS 6- is used to put in and activate the watch face.
Let’s discover the small print:
Creating the watch face templates
The watch face is created from a template, itself designed in Watch Face Designer. That is our new Figma plugin that lets you create Watch Face Format watch faces immediately inside Figma.
The plugin permits the watch face to be exported in a vary of various methods, together with as Watch Face Format (WFF) sources. These can then be simply integrated as property inside the Androidify app, for dynamically constructing the finalized watch face.
Packaging and validation
As soon as the template and avatar have been mixed, the Moveable Asset Compiler Package (Pack) is used to assemble an APK.
In Androidify, Pack is used as a native library on the telephone. For extra particulars on how Androidify interfaces with the Pack library, see the GitHub repository.
As a remaining step earlier than transmission, the APK is checked by the Watch Face Push validator.
This validator checks that the APK is appropriate for set up. This consists of checking the contents of the APK to make sure it’s a legitimate watch face, in addition to some efficiency checks. Whether it is legitimate, then the validator produces a token.
This token is required by the look ahead to set up.
Sending the watch face
The Androidify app on Put on OS makes use of WearableListenerService to pay attention for occasions on the Wearable Information Layer.
The telephone app transfers the watch face through the use of a mixture of MessageClient to arrange the method, then ChannelClient to stream the APK.
Putting in the watch face on the watch
As soon as the watch face is acquired on the Put on OS machine, the Androidify app makes use of the brand new Watch Face Push API to put in the watch face:
val wfpManager =
WatchFacePushManagerFactory.createWatchFacePushManager(context)
val response = wfpManager.listWatchFaces()
strive {
if (response.remainingSlotCount > 0) {
wfpManager.addWatchFace(apkFd, token)
} else {
val slotId = response.installedWatchFaceDetails.first().slotId
wfpManager.updateWatchFace(slotId, apkFd, token)
}
} catch (a: WatchFacePushManager.AddWatchFaceException) {
return WatchFaceInstallError.WATCH_FACE_INSTALL_ERROR
} catch (u: WatchFacePushManager.UpdateWatchFaceException) {
return WatchFaceInstallError.WATCH_FACE_INSTALL_ERROR
}
Androidify makes use of both the addWatchFace or updateWatchFace methodology, relying on the state of affairs: Watch Face Push defines an idea of “slots” – what number of watch faces a given app can have put in at any time. For Put on OS 6, this worth is in truth 1.
Androidify’s method is to put in the watch face if there’s a free slot, and if not, any current watch face is swapped out for the brand new one.
Setting the lively watch face
Putting in the watch face programmatically is a superb step, however Androidify seeks to make sure the watch face can also be the lively watch face.
Watch Face Push introduces a brand new runtime permission which have to be granted to ensure that apps to have the ability to obtain this:
com.google.put on.permission.SET_PUSHED_WATCH_FACE_AS_ACTIVE
As soon as this permission has been acquired, the wfpManager.setWatchFaceAsActive() methodology will be referred to as, to set an put in watch face to being the lively watch face.
Nevertheless, there are a selection of concerns that Androidify has to navigate:
-
setWatchFaceAsActive can solely be used as soon as.
-
SET_PUSHED_WATCH_FACE_AS_ACTIVE can’t be re-requested after being denied by the person.
-
Androidify may already be answerable for the lively watch face.
For extra particulars see how Androidify implements the set lively logic.
Get began with Watch Face Push for Put on OS
Watch Face Push is a flexible API, equally suited to enhancing Androidify as it’s to constructing fully-featured watch face marketplaces.
Maybe you’ve gotten an current telephone app and are on the lookout for alternatives to additional have interaction and delight your customers?
Or maybe you’re an current watch face developer trying to create your personal neighborhood and gallery via releasing a market app?
Check out these sources:
And in addition take a look at the accompanying video for a greater-depth have a look at how we introduced Androidify to Put on OS!
We’re trying ahead to what you’ll create with Watch Face Push!


