Android Wear Code Lab
description
Transcript of Android Wear Code Lab
Android Wear Code LabSetup and Run Sample App
05-29-2014
+GerardCordero
OptimizedPrime.com
@GerardCordero
Requirements
You need to complete the pre-lab preparation:http://www.slideshare.net/optimizedprime/android-wear-code-lab-preparation
Setup Android Wear Virtual Device
15 minutes
Android Virtual Device Manager
● Run Eclipse● Window > Android Virtual Device
Manager
New Virtual Device
● Click New
Setup the Wearable Virtual DeviceSquare Device Round Device
Start your Virtual Device
● Select your wearable device● Click Start
Launch Options
● Click Launch
Booting Up
Installing the Android Wear Preview App
Installed on your Android 4.3+ Phone
10 minutes
Opt-In to test Android Wear Preview app
On the email you got back during the pre-requisites, click “Opt-in to become a tester”
Become a Tester
Click on Become a Tester
Initiate Download
Click “Download it from the Play Store”
Pick a Phone to Install Preview App
The phone you choose will be what you will use in the code lab. Click Install
Done
Click OK
Setup Sample AppRecipe Assistant
15 minutes
Import into Eclipse
● Run Eclipse● File > Import● Android > Existing Android Code Into
Workspace● Click Next
Open Recipe Assistant
● Click Browse● Go to your extracted AndroidWearPreview
folder > samples > Recipe Assistant● Click Open
Rename and Finish
● Click on MainActivity, and rename it to Recipe Assistant
● Select “Copy projects into workspace”
● Click Finish
Delete mipmap-xxxhdpi Folder
● Go to the res folder● Delete the mipmap-xxxhdpi folder (right-click
> Delete in Eclipse)● This causes problems, and is safe to delete
Create and Populate libs Folder
● On your Project’s Root Folder, create a libs folder
● Copy android-support-v4.jar to libs folder (jar file is in Android ADT folder > sdk > extras > android > support > v4)
● Copy wearable-preview-support.jar to libs folder (in extracted AndroidWearPreview)
Add Jar Files to Build
● In Eclipse, right-click > Refresh the Project● Open libs● For each jar file, right-click > Build Path >
Add to Build Path● Entries will show up on Referenced Libraries
Move Contents of java to src folder
● Open Finder or Windows Explorer● Go to your Recipe Assistant project folder● Move the contents of the “java” folder into
the “src” folder● This project is originally an Android Studio
project, but Eclipse goes to the src folder for classes. This step fixes the Class not found error
● In Eclipse, right-click the Project > Refresh
Download the Finished Code
● For your convenience, here’s the code:https://github.com/GerardCordero/AndroidWear/tree/master/RecipeAssistant
Setup your PhoneEnable phone to talk to Android Wear
emulated device
15 minutes
Boot up your Android Wear virtual device
If you haven’t done so, boot it up now
Turn on USB Debugging on Phone
● On your phone, go to Settings > Developer Options
● Make sure Developer Options is turned on● Make sure USB Debugging is turned on● Note: Developer Options location may vary
by phone
Getting your ADB’s Path
● Note: this is for the next two steps● Go to Android SDK Manager● Get SDK Path’s value, that is your base
folder● In Finder/Windows Explorer, go to that path● then go platform-tools
Plug in your Phone to Computer
● Unlock your phone● Plug it to your computer via USB cable● Confirm it’s running by running this
command (from command-line):○ ./adb devices
● You should see two entries (one for wearable, one for your phone). Both should have “device” on it
Run adb forward
● While in the command-line, run this:○ ./adb -d forward tcp:5601 tcp:5601
● You will see a “g” at the top-right corner of your wearable virtual device
Confirm on your Android Wear Preview App
● On your Phone, open the Android Wear Preview app
● It should say “Connected”
Run Recipe Assistant 10 Minutes
Run as Android Application
● From Eclipse, right-click on the Project > Run As > Recipe Assistant
● On the list, pick your phone● Click OK
Send a Recipe to your Wearable
● From your phone’s Recipe Assistant, pick a Recipe
● Click Start on the Action bar (top-right)