Android Wear Developer Preview: Using Xamarin Jar Binding
With wearable technology evolving every day, and from the first attempts of "smart" watches till smart watches today, developers are getting more interested to be a part of this movement that we could call an extension of mobile development. It is a similar concept as when Google started with Android as an open source OS, the recently announced Android Wear is also open for developers to work on their own ideas and test them on the watch.
Naturally I couldn’t resist the temptation to start looking at the preview and wonder what I can do. We are all excited with the new developer preview for Android Wear and as soon as we got the approval email we started to code in order to get it working with Xamarin.
First of all you'll need to complete the prerequisites and follow the instructions from Google using step 1 to 3. In order to download the preview support library and receive access to the Android Wear Preview beta app on Google Play Store, these steps need to be completed.
Just a comment here. In the step 3 we should use a Mobile Phone with Android 4.3 or higher. Tablets are not supported in the initial release of the developer preview, yet. However, you shouldn't have any further problems working with mobile devices.
Now the fun starts by creating a new solution with Xamarin. We will create a new C# -> Android -> Android Java Bindings Library.
For this step we will name the project Android.Preview and the solution WearPOC.
Now we will look into the zip file that Google sent us previously, for the file namedwearable-preview-support.jar (Warning: This file could change on further releases of the preview) and we will add it to the Jars folder in our project.
It is important to verify that the Build action for the .jar file is EmbededJar, after that we will add a reference to Mono.Android.Support.v4.
Now we can build our own project and the jar binding should throw a beautiful “Build successful”.
The next step is creating an Android Application, in this case we named it ITexicoWearAppand it should configured as the Startup Project for the solution.
Then we edit the ITexicoWearApp project references to add the Android.Preview binding project and the Mono.Android.Support.v4 as we added to the binding project.
Now we will open our MainActivity.cs file and add the following headers:
Replace the button. Click delegate implementation with:
var PageStyle = new NotificationCompat.BigTextStyle();
PageStyle.BigText("Our POC is complete!");
var Notification = new NotificationCompat.Builder (this)
.SetLargeIcon (Android.Graphics.BitmapFactory.DecodeResource(Resources ,Resource.Drawable.Icon))
.SetContentTitle ("Hello Wear!")
.Notify ("multi-page-notification", 500, Notification);
We will save our project and it is show time!!
To continue, just follow the next steps:
1. - Run the Android Wear Emulator.
2. - Connect your Android Phone.
3.- Execute ./dab -d forward tcp:5601 tcp:5601 as being told in the Google documentation.
4. - Execute your program from Xamarin to the device and press the button.
With this you will have an initial setup and be ready to start playing with this exciting new tool.
Note: Android Wear Developer Preview is a work in progress and the items described here may change on future versions.
About the Author
Daniel Miranda is a Computer Electronics Engineer with 8+ years of experience in .Net Development. He jumped to Xamarin and he's creating Android and iOS apps here at iTexico.