Getting Started

PDF for offline use:
Sample Code:

Let us know how you feel about this.


0/250
Thanks for the feedback!

Create your first Android Wear app and run it on the Wear emulator.

Your first Wear app

Follow these steps to create your first Xamarin.Android Wear app:

1. Create new Android project

Create a new Android Wear Application:

This template automatically includes the Xamarin Android Wearable Library NuGet (and dependencies) so you'll have access to Wear-specific controls.

If you don't see the Wear template, double-check you've installed a supported Android SDK (API 20 or 21).

2. Choose the correct Target Framework

Ensure the target framework is set to Android 5.0 (Lollipop) (or the earlier 4.4.87 with Wear support):

3. Edit the Main.axml layout

Configure the layout to contain a TextView and a Button for the sample:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
  <ScrollView
    android:id="@+id/scroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#000000"
    android:fillViewport="true">
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:text="Main Activity"
        android:textSize="36sp"
        android:textColor="#006600" />
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:textColor="#cccccc"
        android:id="@+id/result" />
      <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="showNotification"
        android:text="Click Me!"
        android:id="@+id/click_button" />
    </LinearLayout>
  </ScrollView>
</FrameLayout>

4. Edit the MainActivity.cs source

Add the code to increment a counter and display it whenever the button is clicked:

[Activity (Label = "WearTest", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
  int count = 1;

  protected override void OnCreate (Bundle bundle)
  {
    base.OnCreate (bundle);

    SetContentView (Resource.Layout.Main);

    Button button = FindViewById<Button> (Resource.Id.click_button);
    TextView text = FindViewById<TextView> (Resource.Id.result);

    button.Click += delegate {
      text.Text = string.Format ("{0} clicks!", count++);
    };
  }
}

5. Run the Android Wear app

Be sure to choose the correct Wear simulator before you start debugging:

Don't be surprised if you see this (or another interstitial screen) at first. The watch emulator can take a while to start up:

Eventually you'll be rewarded with your first Xamarin.Android Wear app:

Next Steps

Check out the samples including Android Wear apps with companion Phone apps.

When you are ready to distribute your app, read the packaging notes.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.