Getting Started With Android Wearable Using Xamarin and Visual Studio

What are Wearable Devices

The terms “wearable devices“, and “wearables” all refer to electronic technologies or computers that are incorporated into items of clothing and accessories that can comfortably be worn on the body. Examples are Google Glass and Smart Watches.

I had the opportunity to explore on android wearable devices, particularly smart watches and have decided to use Xamarin and Visual Studio for the following reasons.

  • Xamarin allows you to build cross-platform apps (iOS, Andriod and Windows app) using C#.
  • I am an experienced C# developer.
  • I am more familiar with Visual Studio development tools.
  • Gives me less learning curve as I don't need to learn how to use other frameworks, editors, tools and other programming languages to build native apps.
  • I can take advantage of the cool features provided by Xamarin such as cloud testing and app monitoring.
  • Xamarin and Visual Studio are quite popular and stable platform for building real world apps.

Having the opportunity to work with android wearable is very exciting as this is getting more popular nowadays. Yes it's exciting but at the same time scary because I don't have any much experience on the technology, smart watch device and android stuffs. This means that I will need to learn from scratch about how everything works with this technology and the android framework itself. I am also aware that there's a bit of learning curve to deal with as working with this technologies is completely different compared to web development. So that's why I'm writing this article to guide new comers like me to get started with Android Wear application development.

Setting up the Development Environment

The first thing we need is to install the necessary tools. So first you need to install Visual Studio. If you are using Visual Studio 2010, 2012 or 2013 then make sure it's a professional or higher version because the Xamarin extension for Visual Studio will only be supported for non-express editions. See https://xamarin.com/faq for details.

In my case I have used Visual Studio 2013 Ultimate version. Once you have installed the supported version of Visual Studio then go ahead and download the Xamarin extension for Visual Studio here http://xamarin.com/visual-studio. (You can start with a free trial or a license version of it).

Just follow the instructions in the download wizard until it's complete ( note that this may take longer depending on the frameworks that you are installing). You may need to restart your machine to reflect everything that is installed in your machine.

Now when you launch Visual Studio, you should be able to see the following items below under Tools menu.



To ensure that everything you need is installed, you can verify it at the Android SDK Manager. Just go to Tools > Android > Android SDK Manager. This will open the following window below:



Now if you think that everything you need was installed then congratulations you can now start creating your own awesome android app using Xamarin within Visual Studio.

Creating a Simple Android Wear Application

Let's go ahead and create a new project within Visual Studio and then from the Templates select Android > Wear App (Android). You should be able to see something as in the following.



Just click OK to let Visual Studio generate the necessary files to build wear app for you. The image below shows the generated files with default sample codes for you to get started working on building wear apps.



That was easy right? Here's the Anatomy of Xamarin.Android Application that is taken from the official documentation here: http://developer.xamarin.com/guides/android/getting_started/.

Folder Purpose
References Contains the assemblies required to build and run the application. If we expand the References directory, we'll see references to .NET assemblies such as System, System.Core and System.Xml, as well as a reference to Xamarin's Mono.Android assembly.
Components The Components directory houses ready-made features from the Xamarin Components store, a public marketplace for Xamarin code. For more information on Xamarin Components, refer to the Xamarin Components walkthrough.
Assets Contains the files the application needs to run including fonts, local data files and text files. Files included here are accessible through the generated Assets class. For more information on Android Assets, see the Xamarin Using Android Assets guide.
Properties Contains the AndroidManifest.xml file that describes all the requirements for our Xamarin.Android application, including name, version number and permissions. The Properties folder also houses AssemblyInfo.cs, a .NET assembly metadata file. It is good practice to fill this file with some basic information about your application.
Resources Contains application resources such as strings, images and layouts. We can access these resources in code through the generated Resource class. The Android Resources guide provides more details about the Resources directory. The application template also includes a concise guide to Resources in the AboutResources.txt file.

Running the Application

In order for us to run the application we need to first setup an emulator. You can create one by following these few steps.

Go to Tools > Andriod > Andriod Emulator Manager or simply click on the AVD icon at the tool bar. See below.



The Android Device Manager window should show. This is where we can edit, start, create, delete or repair virtual devices. Now click on the "Create" button. The following window should open that allows you to select the device that you want to create. In this case, we just need to create a virtual Android Wear Device for us to run our application in the emulator.



Once everything is set then just click OK to create the emulator. Once done then you should be able to see the device that you have just created.



Just click Start > Launch to run the emulator in the background. Note that it may take some time to load the emulator. When the emulator is loaded and ready, you should be able to see the name of the virtual device that you have just created in the start debugging dropdown as in the following.



Now set your application as the startup project and then run it by pressing F5. Here's the sample output of the wear application that is running within the emulator.



If you want to refer to wear app examples then just visit this link: http://developer.xamarin.com/samples/android/Android Wear/

That's it. I hope someone finds this article useful.

In my next article, I will show how to do debugging, installing and un-installing wear apps within a real wearable device. So stay tuned.


Similar Articles