Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Wear Projects

You're reading from   Android Wear Projects Create smart Android Apps for Wearables

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781787123229
Length 416 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ashok Kumar S Ashok Kumar S
Author Profile Icon Ashok Kumar S
Ashok Kumar S
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting You Ready to Fly - Setting Up Your Development Environment FREE CHAPTER 2. Let us Help Capture What is on Your Mind - WearRecyclerView and More 3. Let us Help Capture What is on Your Mind - Saving Data and Customizing the UI 4. Measure Your Wellness - Sensors 5. Measuring Your Wellness and Syncing Collected Sensor Data 6. Ways to Get Around Anywhere - WearMap and the GoogleAPIclient 7. Ways to Get Around Anywhere - UI controls and More 8. Let us Chat in a Smart Way - Messaging API and More 9. Let us Chat in a Smart Way - Notifications and More 10. Just a Face for Your Time - WatchFace and Services 11. More About Wear 2.0

Creating your first Android Wear application

In this section, let's understand the essential steps required to create your first Wear project.

Before you continue to create your application, ensure you have one complete version of Android installed with a Wear system image and you have the latest version of Android Studio.

The following picture is the initial interface of Android Studio. In this window, one can import legacy ADT Android projects, configure the Android SDK, and update Android Studio.

Android Studio welcome window with basic controls for getting started:

Creating your first Wear project

Click on the Start a new Android Studio project option in the Android Studio window. You will be prompted by another window with project details.

The following screenshot shows the window that allows users to configure their project details, such as project name, Package name, and whether the project needs native C++ support:

You can name your project as you wish. After you have chosen your project name and your project local system location, you can press the Next button in the window, which brings up another window with a few configuration queries, as shown in the following screenshot:

In this window, you can choose to write a standalone Wear application if you uncheck the Phone and Tablet option. In this way, you will see only Wear application templates:

Now, Android Studio templates prompt only Android Wear activity templates with the following set of options:

  • Add No Activity
  • Always On Wear Activity
  • Blank Wear Activity
  • Display Notification
  • Google Maps Wear Activity
  • Watch Face

The activity template chooser helps you to access the default boilerplate codes, which are already templatized and can be used directly in projects:

To create the first project, we will choose Blank Wear Activity and click on the Next button in the window. Android Studio will prompt another window for creating the name of the activity and layout file. In this template, the two form factors of Android Wearable devices, which are mostly round and square shapes, are prepopulated with the boilerplate code stub:

When your project is ready to be created, click on the Finish button. After clicking on Finish, Android Studio will take a few moments to create the project for us.

Way to go! You have now created a working boilerplate code for the Android Wear standalone application without the phone companion application. When successfully created, you will see the following files and codes added to your project by default:

If your SDK is not updated with API level 25, you might see the Wear option in the Android Studio project creating prompts with Android Wear support library 1.x; you can update this in the Wear module Gradle file with the following dependency:

compile 'com.google.android.support:wearable:2.0.0'

Creating a Wear emulator

The process of creating a Wear emulator is very similar to creating a phone emulator.

In the AVD manager, click on the Create Virtual Device... button:

Choose the required form factor emulator according to your application needs. Now, let's create the Android Wear square emulator:

After selecting the right emulator for your Wear, you will get another prompt to choose the Wear operating system. Let's choose the API Level 25 Nougat emulator, as shown in the following screenshot:

The last prompt asks for the emulator name and other orientation configurations based on your needs:

Way to go! Now, we have successfully created a square form factor emulator for the project. Let's run the project that we have created in the emulator:

Google recommends developing Wear apps in the actual hardware device to have the best user experience. However, working on emulators has the benefit of creating different screen form factors to check the application's rendering.

Working with actual Wear device

  1. Open the settings menu on the Wear device
  2. Go to About device
  3. Click on the build number seven times to enable developer mode
  4. Now enable ADB debugging on the watch

You can now connect the Wear device directly to your machine with the USB cable. You can debug your applications over Wi-Fi and Bluetooth with the following setups.

Debugging over Wi-Fi

Make sure your watch has the developer options enabled. Debugging over Wi-Fi is possible only when the Wear device and machine are connected to the same network.

  • In the Wear device developer option, tap on Debug over Wi-Fi
  • The watch will display its IP address (for example, 192.168.1.100). Keep a reference; we need this for the next step.
  • Connect the debugger to the device
  • Using the following command, we can attach the actual device to the ADB debugger:
adb connect 192.168.1.100

Enable Bluetooth debugging

We need to ensure debugging is enabled in developer options, as follows:

adb forward tcp:4444 localabstract:/adb-hub
adb connect
127.0.0.1:4444

In your Android Wear, just allow ADB Debugging when it asks.

Now that we have a working setup of our development environment, let's understand the basic Android Wear-specific UI components.

You have been reading a chapter from
Android Wear Projects
Published in: Jul 2017
Publisher: Packt
ISBN-13: 9781787123229
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image