Android Tutorial Creating and Packaging a Wear App

This tutorial will show you how to create an app for a Wearable device and how to package it so it auto installs.

What is Android Wear?
For those that do not know, Google has released a new branch of the Android platform designed for Wearables. The current 'Wearable' devices are smartwatches. Namely the Samsung Gear Live, LG G Watch with the Moto 360 due soon and a few others just being announced.

More can be found here

What are we achieving and why does it require a tutorial?
We are trying to achieve the actions of creating an app for Wear devices and getting it installed on the device. Android Wear devices do not have direct access to an app market. Wear apps must have a handheld counterpart. Basically, you install the handheld app from the appropriate market place. Within that handheld app you package your Wear app. This process I believe is something that has never been done with B4A.

Here goes...

Creating the app for the Wearable device.
Apps for Wearables should obviously take into account the screen size and features available on the target device. The current watches are 280x280 or 320x320 screens so we don't have as much real estate. They are also very small screens so you should make your layouts simple with large interaction view for easy tapping. There is an unofficial UI library for Wearable devices, something I hope will be made into a B4A lib soon. Until then, standard views are support out of the box or you could create your own custom views. The Wear app should mainly be used for displaying info and interacting with the wear device sensors. Intensive computing operations and network access should be done by the handheld and the results passed to the Wearable with the DataLayer. The DataLayer is a library I am currently working on. I was hoping to have it completed before this tutorial, but I feel it is simply taking too long. Hopefully it won't be long now.

OK, let's get down to the good stuff.
Create a new project in B4A and some UI and code. This can be anything you like really, Wear devices support most Android APIs and have a few sensor too (Accelerometer, Gyro, Compass). Set the package name to whatever your normal convention suits. The recommended theme for Wearables is Theme.DeviceDefault.Light. Set this by adding the following in the manifest editor.

B4X:
SetApplicationAttribute(android:theme, "@android:style/Theme.DeviceDefault.Light")

You must edit your SDK levels and add a feature to the in the manifest. The final result should be
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20"/>
<uses-feature android:name="android.hardware.type.watch"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

SetApplicationAttribute(android:theme, "@android:style/Theme.DeviceDefault.Light")

Once you are happy with the app, compile the project without a device connected to the pc. This will produce the .apk under project/Objects/.

Create the Handheld counterpart
Next create the handheld app, again, whatever UI / code you like. Set the package name exactly the same as you did in the Wearable app. The DataLayer will again be used eventually to send / receive data between the 2.

Add the following to the manifest editor

B4X:
AddApplicationText(
<meta-data android:name="com.google.android.wearable.beta.app"
    android:resource="@xml/wearable_app_desc"/>
)
I'm assuming the 'beta' will be dropped eventually.
Also, target SDK version 20. Min SDk version 14.

Tying the 2 together
Now go to the project folder for the handheld app. Create a folder called 'raw' with the Objects/res/ directory. Also, create an 'xml' folder if it doesn't exist already. So you have this
DirStructure.jpg


Next inside the /xml/ create a new xml file and add the following code.
B4X:
<?xml version="1.0" encoding="utf-8"?>
<wearableApp package="barxdroid.wearable_app">
    <versionCode>1</versionCode>
    <versionName>1.0</versionName>
    <rawPathResId>wearable_app</rawPathResId> '<-- replace with name of your Wearable APK file (minus the '.apk')
</wearableApp>
Save the file as 'wearable_app_desc.xml' and make the file read-only.

Copy the .apk file of your Wearable app into the /raw/ file and make that read-only also.

Finally...

The last step is to compile you handheld app. This will package the Wearable app inside the handheld .apk, because we put it in the /raw/.

Now when you install the app onto your phone/tablet that is connected to a Wear device it will automatically install the Wear app to the Wear device.

You can check and launch the app by doing the following:
On the Wear device:
* Tap the screen ('Speak Now' will show)
* Scroll down the page until you see 'Start' and tap that
* You should see your app in the list.

I Hope this is of use to some, I was going to wait until I had the DataLayer lib ready to show a more complete setup but I feel bad for keeping this to myself While the lib is taking time.

Attached are the 2 demo projects (Wearable and Handheld)

Note: will probably make this prettier when I have a little more time.
 

Attachments

  • WearTest(handheld).zip
    109.1 KB · Views: 676
  • WearTest(wearable).zip
    5.5 KB · Views: 607
Last edited:

green2000

New Member
Licensed User
Ah...I see now and also learned about Tizen!

As Shara Tibken wrote on CNET "For now, Samsung's greatest hope for Tizen -- and the way to get the operating system into consumers' homes, almost without them even knowing it -- will come through Gear."

Thanks!!
 

aaronk

Well-Known Member
Licensed User
I think something has broken somewhere..

I complied my Wear app fine, and copied it to the correct folder in my phone app, but when I compile the Phone app I get this error:

B4X:
B4A version 4.30
Parsing code.  0.02
Compiling code.  0.03
 
ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code.  0.02
Generating R file.  Error
AndroidManifest.xml:15: error: Error: No resource found that matches the given name (at 'resource' with value '@xml/wearable_app_desc').

My phone app has nothing in it (just the B4A default template) and I copied the manifest text from the sample that was posted in post 1.

Has something changed now?
 

Troberg

Well-Known Member
Licensed User
What is the difference between these devices and the watch form factor devices that are a full device, with phone and everything (such as many of the ones found here: http://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20150310021546&SearchText=android+watch , for example this: [url]http://www.aliexpress.com/item/High-Quality-TW810-Bussiness-Smart-Watch-Phone-Stainless-Steel-Bluetooth-Intelligent-Wristwatch-Mp3-Mp4-Player-Mini/32241933200.html).[/URL]

Are the "full devices" just like any other Android device, although with a smaller screen?
 

barx

Well-Known Member
Licensed User
What is the difference between these devices and the watch form factor devices that are a full device, with phone and everything (such as many of the ones found here: http://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20150310021546&SearchText=android+watch , for example this: http://www.aliexpress.com/item/High...istwatch-Mp3-Mp4-Player-Mini/32241933200.html).

Are the "full devices" just like any other Android device, although with a smaller screen?


Wear devices run a branch of the android platform put together by google to try and standardize wearables. the devices you speak of I believe basically run a full version of android (though it probably has a lot of bloat removed). There are generally no sdk's or standard communication channels implemented in such devices.
 

barx

Well-Known Member
Licensed User
Idon't believe the SW2 is a Wear device. the SW3 is. So n, the SW2 won't work here. Sorry
 

Mark Thorndyke

Member
Licensed User
Idon't believe the SW2 is a Wear device. the SW3 is. So n, the SW2 won't work here. Sorry

I had cottoned on late Thursday evening but still continued with the emulator. Has personal appeal for scenarios when play racquet sports and having a smartwatch on one player and tablet on the sidelines. Something I'd thought about early last year when getting a SW2. Time to upgrade
 

barx

Well-Known Member
Licensed User
Will this library work on the Samsung Gear S
Thank you!

This is for devices that run Android Wear. I believe the Gear S runs Tizen.
 

gezueb

Active Member
Licensed User
Hi Barx, I tried your example and it works okay on my Moto 360 II. Then I changed the code slightly of the wearable (relocated the position of the label) and recompiled it according to your tutorial. Everything works without error messages. But the wearable program still displays the same test programm as downloaded (no change). Any idea what I should do differently? Thanks for your help, Georg
 

gezueb

Active Member
Licensed User
Ok, found the solution: The app must be uninstalled on the mobile before recompiling the pack, then it gets also properly (re-)installed on the watch.
Georg
 

gezueb

Active Member
Licensed User
Dim mode / ambient mode
Is there a way to configure a wearable app so it keeps running in dim mode? I have "always on" set in the Android Wear APP, but after the time out my app stops and the last app that run previuosly is started.
 

gezueb

Active Member
Licensed User
Dim mode:
Found out myself: The Phonewakestate Object from the phone library works on the watch as well! Just enable "keep_awake" in the wearable app and that's it.
 

NeoTechni

Well-Known Member
Licensed User
I changed the app name of the wearable, and changed barxdroid.wearable_app in the XML file to match, but now when I recompile it won't show on the watch. What am I doing wrong? (I did set the XML and APK to read only)
 
Last edited:
Top