Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a27d18f2 authored by Robert Ly's avatar Robert Ly Committed by Android Git Automerger
Browse files

am 3f737f2c: am e1beb730: Merge "docs: wear training classes" into klp-modular-dev

* commit '3f737f2c':
  docs: wear training classes
parents 911db418 3f737f2c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
page.title=Building Apps for Wearables
page.trainingcourse=true

@jd:body


<p>These classes teach you how to build notifications in a handheld app that are automatically
synced to wearables as well as how to build apps that run on wearables.</p>
 No newline at end of file
+84 −1
Original line number Diff line number Diff line
@@ -638,7 +638,6 @@ include the action bar on devices running Android 2.1 or higher."
            </li>
        </ul>
      </li>

    </ul>
  </li>
  <!-- End connectivity and cloud -->
@@ -727,6 +726,90 @@ include the action bar on devices running Android 2.1 or higher."
  <!-- End privacy and location -->


  <li class="nav-section">
    <div class="nav-section-header">
      <a href="<?cs var:toroot ?>training/building-wearables.html">
      <span class="small">Building Apps for</span><br/>
              Wearables
      </a>
    </div>
    <ul>
      <li class="nav-section">
        <div class="nav-section-header">
          <a href="<?cs var:toroot ?>training/wearables/notifications/index.html"
             description="How to build handheld notifications that are synced to
             and look great on wearables."
            >Adding Wearable Features to Notifications</a>
        </div>
        <ul>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/notifications/creating.html">Creating a Notification</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/notifications/voice-input.html">Receiving Voice Input in a Notification</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/notifications/pages.html">Adding Pages to a Notification</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/notifications/stacks.html">Stacking Notifications</a>
          </li>
        </ul>
      </li>

      <li class="nav-section">
        <div class="nav-section-header">
          <a href="<?cs var:toroot ?>training/wearables/apps/index.html"
             description="How to build apps that run directly on wearables."
            >Creating Wearable Apps</a>
        </div>
        <ul>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/apps/creating.html">Creating and Running a Wearable App</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/apps/layouts.html">Creating Custom Layouts</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/apps/voice.html">Adding Voice Capabilities</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/apps/packaging.html">Packaging Wearable Apps</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/apps/bt-debugging.html">Debugging over Bluetooth</a>
          </li>
        </ul>
      </li>

      <li class="nav-section">
        <div class="nav-section-header">
          <a href="<?cs var:toroot ?>training/wearables/data-layer/index.html"
             description="How to sync data between handhelds and wearables."
            >Sending and Syncing Data</a>
        </div>
        <ul>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/data-layer/accessing.html">Accessing the Wearable Data Layer</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/data-layer/data-items.html">Syncing Data Items</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/data-layer/assets.html">Transferring Assets</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/data-layer/messages.html">Sending and Receiving Messages</a>
          </li>
          <li>
            <a href="<?cs var:toroot ?>training/wearables/data-layer/events.html">Handling Data Layer Events</a>
          </li>
        </ul>
      </li>
    </ul>
  </li>

  <!-- End Building for wearables -->

  <li class="nav-section">
    <div class="nav-section-header">
+92 −0
Original line number Diff line number Diff line
page.title=Debugging over Bluetooth

@jd:body

<div id="tb-wrapper">
  <div id="tb">

    <!-- Required platform, tools, add-ons, devices, knowledge, etc. -->
    <h2>This lesson teaches you to</h2>
    <ol>
      <li><a href="#SetupDevices">Set Up Devices for Debugging</a></li>
      <li><a href="#SetupSession">Set Up a Debugging Session</a></li>
      <li><a href="#DebugApp">Debug Your App</a></li>
    </ol>
    <h2>You should also read</h2>
    <ul>
      <li><a href="{@docRoot}design/wear/index.html">Android Wear Design Principles</a></li>
    </ul>
  </div>
</div>

<p>You can debug your wearable over Bluetooth by routing it's debug output to the
handheld device that's connected to your development machine.</p>

<h2 id="SetupDevices">Setup Devices for Debugging</h2>
<ol>
  <li>Enable USB debugging on the handheld:
    <ul>
      <li>Open the Settings app and scroll to the bottom.</li>
      <li>If it doesn't have a Developer Options setting, tap <b>About Phone</b>
      (or <b>About Tablet</b>), scroll to the bottom, and tap the build number 7 times.</li>
      <li>Go back and tap <b>Developer Options</b>.</li>
      <li>Enable <b>USB debugging</b>.</li>
    </ul>
  </li>
  <li>Enable Bluetooth debugging on the wearable:
    <ol>
      <li>Tap the home screen twice to bring up the Wear menu. </li>
      <li>Scroll to the bottom and tap <b>Settings</b>.</li>
      <li>Scroll to the bottom. If there's no <b>Developer Options</b> item, tap <b>About</b>,
      and then tap the build number 7 times.</li>
      <li>Tap the <b>Developer Options</b> item.</li>
      <li>Enable <b>Debug over Bluetooth</b>.</li>
    </ol>
  </li>
</ol>

<h2 id="SetupSession">Set Up a Debugging Session</h2>
<ol>
 <li>On the handheld, open the Android Wear companion app.</li>
 <li>Tap the menu on the top right and select <b>Settings</b>.</li>
 <li>Enable <b>Debugging over Bluetooth</b>. You should see a tiny status summary appear under the
 option:
 <pre>
Host: disconnected
Target: connected
</pre>
</li>
<li>Connect the handheld to your machine over USB and run:
<pre>
adb forward tcp:4444 localabstract:/adb-hub; adb connect localhost:4444
</pre>

<p class="note"><b>Note</b>: You can use any available port that you have access to.</p>
</li>
</ol>
<p>
In the Android Wear companion app, you should see the status change to:</p>
<pre>
Host: connected
Target: connected
</pre>

<h2 id="#debug">Debug Your App</h2>

Your wearable should show up as <code>localhost:4444</code> when running <code>adb devices</code>.

To run any <code>adb</code> command, use this format:

<pre>adb -s localhost:4444 &lt;command&gt; </pre>

<p>If there are no other devices connected over TCP/IP (namely emulators),  you can shorten the command
to:</p>
<pre>
adb -e &lt;command&gt;
</pre>
<p>For example:</p>
<pre>
adb -e logcat
adb -e shell
adb -e bugreport
</pre>
 No newline at end of file
+184 −0
Original line number Diff line number Diff line
page.title=Creating and Running a Wearable App

@jd:body

<div id="tb-wrapper">
<div id="tb">
<h2>This lesson teaches you to</h2>
<ol>
  <li><a href="#SetupEmulator">Set Up an Android Wear Emulator</a></li>
  <li><a href="#SetupDevice">Set Up an Android Wear Device</a></li>
  <li><a href="#CreateProject">Create a Project</a></li>
  <li><a href="#Libraries">Include the Correct Libraries</a></li>
</ol>
<h2>Dependencies and Prerequisites</h2>
  <ul>
    <li>Android Studio 0.8 or later and Gradle 1.12 or later</li>
  </ul>
</div>
</div>

<p>Wearable apps run directly on the wearable device, giving you access to low-level
hardware such as sensors, activities, services, and more, right
on the wearable.</p>

<p>A companion handheld app that contains the
wearable app is also required when you want to publish to the Google Play store.
Wearables don't support the Google Play store, so users download the companion handheld app,
which automatically pushes the wearable app to the wearable. The handheld app is also
useful for doing heavy processing, network actions, or other work and
sending the results to the wearable.
</p>

<p>This lesson goes over how to set up a device or emulator and create one project to contain
both your wearable and handheld apps.
</p>


<h2 id="SetupEmulator">Set Up an Android Wear Emulator or Device</h2>
<p>We recommend that you develop on real hardware so you can better
gauge the user experience. However, the emulator lets you test out different
types of screen shapes, which is useful for testing.</p>

<h3>Set up an Android Wear Virtual Device</h3>

<p>To set up an Android Wear virtual device:</p>
<ol>
  <li>Click <b>Tools > Android > AVD Manager</b>.</li>
  <li>Click <b>Create...</b>.</li>
  <li>Fill in the following details for the AVD you want to specify and leave the rest
  of the fields with their default values:
    <ol>
      <li><b>AVD Name</b> - A name for your AVD</li>
      <li><b>Device</b> - Android Wear Round or Square device types</li>
      <li><b>Target</b> - Android 4.4W - API Level 20</li>
      <li><b>CPU/ABI</b> - Android Wear ARM (armeabi-v7a)</li>
      <li><b>Keyboard</b> - Select <b>Hardware keyboard present</b></li>
      <li><b>Skin</b> - AndroidWearRound or AndroidWearSquare depending on the selected device type</li>
      <li><b>Snapshot</b> - Not selected</li>
      <li><b>Use Host GPU</b> - Selected, to support custom activities for wearable notifications</li>
    </ol>
  </li>
  <li>Click <b>OK</b>.</li>
<li>Start the emulator:
<ol>
  <li>Select the virtual device you just created.</li>
  <li>Click <b>Start...</b>, then click <b>Launch</b>.</li>
  <li>Wait until the emulator initializes and shows the Android Wear home screen.</li>
</ol>
</li>
<li>Pair Your handheld with the emulator:
<ol>
  <li>On your handheld, install the Android Wear app from Google Play.</li>
  <li>Connect the handheld to your machine through USB.</li>
  <li>Forward the AVD's communication port to the connected handheld device (you must
  do this every time the handheld is connected):
  <pre>adb -d forward tcp:5601 tcp:5601</pre>
  </li>
  <li>Start the Android Wear app on your handheld device and connect to the emulator.</li>
  <li>Tap the menu on the top right corner of the Android Wear app and select
  <b>Demo Cards</b>.</li>
  <li>The cards you select appear as notifications on the home screen of the emulator.</li>
</ol>
</li>
</ol>

<h3 id="SetupDevice">Set Up an Android Wear Device</h3>
<p>To set up an Android Wear device:</p>
<ol>
  <li>Install the Android Wear app, available on Google Play, on your handheld.</li>
  <li>Follow the app's instructions to pair your handheld with your wearable.
  This allows you to test out synced handheld notifications, if you're building them.</li>
  <li>Connect the wearable to your machine through USB, so you can install apps directly to it
  as you develop.</li>
</ol>

<h2 id="CreateProject">Create a Project</h2>

<p>To begin development, create an app project that contains
 wearable and handheld app modules. In Android Studio, click <b>File</b> >
 <b>New Project</b> and follow the Project Wizard instructions, as described in
 <a href="{@docRoot}sdk/installing/create-project.html">Creating a
Project</a>. As you follow the wizard, enter the following information:</p>

<ol>
  <li>In the <b>Configure your Project</b> window, enter a name for your app and a package
  name.</li>
  <li>In the <b>Form Factors</b> window:
    <ul>
      <li>Select <b>Phone and Tablet</b> and select <b>API 8: Android 2.2 (Froyo)</b>
      under <b>Minimum SDK</b>.</li>
      <li>Select <b>Wear</b> and select <b>API 20: Android 4.4 (KitKat Wear)</b>
      under <b>Minimum SDK</b>.</li>
    </ul>
  </li>
  <li>In the first <b>Add an Activity</b> window, add a blank activity for mobile.</li>
  <li>In the second <b>Add an Activity</b> window, add a blank activity for Wear.

  <p>When the wizard completes, Android Studio creates a new project with two modules, <b>mobile</b> and
  <b>wear</b>. You now have a project for both your handheld and wearable apps that you can create activities,
  services, custom layouts, and much more in. On the handheld app, you do most of the heavy lifting,
  such as network communications, intensive processing, or tasks that require long
  amounts of user interaction. When these are done,
  you usually notify the wearable of the results through notifications or by syncing and sending
  data to the wearable.</p>

  <p class="note"><b>Note:</b> The <b>wear</b> module also contains a "Hello World" activity that uses a
  <code>WatchViewStub</code> that inflates a layout based on whether the device's screen
  is round or square. The <code>WatchViewStub</code> class is one of the UI widgets that's provided
  by the <a href="{@docRoot}training/wearables/apps/layouts#UiLibrary">wearable support library</a>.</p>
</li>

<h2 id="Install">Install the Wearable app</h2>

<p>When developing, you install apps directly to the wearable like with handheld apps. Use
either <code>adb install</code> or the <b>Play</b> button on Android Studio.</p>

<p>When you're ready to publish your app to users, you embed the wearable app inside of the
handheld app. When users install the handheld app from Google Play, a connected wearable automatically
receives the wearable app.</p>

<p class="note"><b>Note:</b> The automatic installation of wearable apps
does not work when you are signing apps with a debug key and only works with release keys. See
<a href="{@docRoot}traiing/wearables/packaging.html">Packaging Wearable Apps</a> for
complete information on how to properly package wearable apps.</p>

<li>
To install the "Hello World" app to the wearable, select <b>wear</b> from the <b>Run/Debug
configuration</b> drop-down menu and click the <b>Play</b> button. The activity shows up on the
wearable and prints out "Hello world!"
</li></ol>
<h2 id="Libraries">Include the Correct Libraries</h2>

<p>As part of the Project Wizard, the correct
dependencies are imported for you in the appropriate module's <code>build.gradle</code> file.
However, these dependencies are not required, so read the following descriptions to find out if you need them or not:</p>

<b>Notifications</b>
<p>The <a href="{@docRoot}tools/support-library/features.html#v4">The
Android v4 support library</a> (or v13, which includes v4)
contains the APIs to extend your existing notifications on handhelds to support wearables.</p>

<p>For notifications that appear only on
the wearable (meaning, they are issued by an app that runs on the wearable), you can just use the
standard framework APIs (API Level 20) on the wearable and remove the support library
dependency in the <b>mobile</b> module of your project.
</p>

<b>Wearable Data Layer</b>
<p>To sync and send data between wearables and handhelds with the Wearable Data Layer APIs,
you need the latest version of
<a href="{@docRoot}google/play-services/setup.html">Google Play services</a>.
If you're not using these APIs, remove the dependency from both modules.</p>

<b>Wearable UI support library</b>
<p>This is an unofficial library that includes UI widgets designed for wearables. We encourage you
to use them in your apps, because they exemplify best practices, but they can still
change at any time. However, if the libraries are updated, your apps won't break since they are compiled
into your app. To get new features from an updated library, you just need to
statically link the new version and update your app accordingly.
This library is only applicable if you create wearable apps.
</p>

<p>In the next lessons, you'll learn how to create layouts designed for wearables as well as how
to use the various voice actions that are supported by the platform.</p>
+72 −0
Original line number Diff line number Diff line
page.title=Creating Wearable Apps
@jd:body

<div id="tb-wrapper">
<div id="tb">
  <h2>Dependencies and Prerequisites</h2>
  <ul>
    <li>Android Studio 0.8 or later and Gradle 1.12 or later</li>
  </ul>
</div>
</div>

<p>
Wearable apps run directly on the device, giving you access to hardware such as sensors and the
GPU. They are fundamentally the same as apps built for other devices using the Android SDK, but
differ greatly in design and usability and the amount of functionality provided.
These are the main differences between handheld and wearable apps:</p>

<ul>
  <li>The system enforces a timeout period. If you are displaying an activity and user's don't
  interact with it, the device sleeps. When it wakes back up, the Wear home screen is displayed
  instead of your activity. If you need to show something persistent, create a notification in the
  context stream instead.</li>
  <li>Wearable apps are relatively small in size and functionality compared to handheld apps.
  They contain only what makes sense on the wearable, which is usually a small
  subset of the corresponding handheld app. In general, you should carry out operations on the
  handheld when possible and send the results to the wearable.
  </li>
  <li>Users don't download apps directly onto the wearable. Instead, you bundle
  the wearable app inside the handheld app. When users install the handheld app,
  the system automatically installs the wearable app. However, for development
  purposes, you can still install the wearable app directly to the wearable.</li>
  <li><p>Wearable apps can access much of the standard Android APIs, but don't support
  the following APIs:</p>
  <ul>
    <li>{@link android.webkit}</li>
    <li>{@link android.print}</li>
    <li>{@link android.app.backup}</li>
    <li>{@link android.appwidget}</li>
    <li>{@link android.hardware.usb}</li>
  </ul>
  <p>
  You can check if a wearable supports a feature by calling
  {@link android.content.pm.PackageManager#hasSystemFeature hasSystemFeature()}
  before trying to use an API.</p>
</li>
</ul>

<p class="note"><b>Note:</b> We recommend using Android Studio for Android Wear development
as it provides project setup, library inclusion, and packaging conveniences that aren't available
in ADT. The rest of this training assumes you're using Android Studio.
</p>

<h2>Lessons</h2>
  <dl>
    <dt><a href="{@docRoot}training/wearables/apps/creating.html">Creating and Running a Wearable App</a></dt>
      <dd>Learn how to create an Android Studio project that
      contains both the wearable and handheld app modules and how to run the app on a device
      or emulator.</dd>
    <dt><a href="{@docRoot}training/wearables/apps/activity.html">Creating Custom Layouts</a></dt>
      <dd>Learn how to create and display custom layouts for notifications and
      activities.</dd>
    <dt><a href="{@docRoot}training/wearables/apps/voice.html">Adding Voice Capabilities</a></dt>
      <dd>Learn how to launch an activity with a voice actions and how to start the
      system speech recognizer app to obtain free-form voice input.</dd>
    <dt><a href="{@docRoot}training/wearables/apps/packaging.html">Packaging Wearable Apps</a></dt>
      <dd>Learn how to package a wearable app inside a
      handheld app. This allows the system to install the wearable app automatically when
      users install the companion handheld app from the Google Play store.</dd>
    <dt><a href="{@docRoot}training/wearables/apps/packaging.html">Debugging over Bluetooth</a></dt>
      <dd>Learn how to debug your wearable over Bluetooth instead of USB.</dd>
  </dl>
 No newline at end of file
Loading