• wear에서 mobile로 전달할 data가 있는 경우 data item, 

    DataMapItem 또는 message, assets등등의 방법을 이용할수 있다. 쌍방의 통신이 필요한경우는 DataItem , DataMapItem을 이용하면되고 일방의 통신의 경우는 Message를 이용할수 있다. (RPC 처럼 사용 가능) 

  • Message를 사용하는 경우(DataItem,DataMapItem의 경우는 사용해보지 않아서 같은지 아직 모름) 일단 네트워크의 node를 확인해야한다. 그리고 가장 가까운 기기기 node(mobile인경우가 대부분)가 접속되었는지, 또 message작업이 가능한지 capability를 확인해야 한다. 그리고 나서 data는 byte[]의 형태로 MessageApi.sendMessage를 통해 전달된다. 그리고 message를 mobile에서 받는 경우 두가지 경우를 생각할수 있다. 
  1. 사용자가 app을 사용하고 있는 경우
  2. 사용자가 app을 사용하지 않고 있는 경우

첫번째 경우에만 통신이 필요한경우는  MessageApi.MessageListener를 inplements 한 activity가 받아들이면된다. 후자의 경우는 service를 이용해서 받는다.

original source :

실제 기기들을 이용해서 하는 debug 설정

mobile은 usb로 개발용 컴퓨터에 연결, wear는 bluetooth를 통해 mobile을 거쳐 r개발용 컴퓨터에 연결하는 방법

Enable Developer Options on your watch

Before you can debug on your watch you must enable developer options. You only need to do this one time. Developer options remain enabled until you disable them.

  1. Open the watch’s Settings.
  2. Tap System > About.
  3. Scroll to Build number and tap the build number seven times.
  4. A dialog will appear confirming that you are now a developer.

Debugging over Bluetooth

Bluetooth debugging only works for Android-paired watches. Before you begin, be sure the watch and phone are paired and you’ve enabled developer options on the watch. You should also be sure that developer options is also enabled on the phone. To check, open the phone’s Settings menu, selectAbout phone and click the build number seven times.

Enable USB debugging on the phone

  1. Open the phone’s Settings menu.
  2. Select Developer Options and enable USB debugging.

Enable ADB/Bluetooth debugging on the watch

  1. Open the watch’s Settings menu.
  2. Scroll to Developer Options.
  3. Confirm that ADB debugging is enabled.
  4. Enable Debug over Bluetooth.

Enable Bluetooth debugging on the phone

(mobile기기에 설치된 android wear 앱의 기본화면)


(mobile기기에 설치된 android wear 앱의 설정화면)


(하단의 Debugging over Bluetooth 을 enale해야한다. 5번 내용)

  1. On the phone, open the Android Wear companion app.
  2. Tap the Settings icon.
  3. Enable Debugging over Bluetooth. A status message appears under the option. It looks like this:
Host: disconnected
Target: connected

At this point the development machine (the host) is not communicating with with the watch (the target). You need to complete the link.

Connect the debugger to the watch

In this final step, you’ll use everything: the debugger, the phone, and the watch.

C:UsersjacobAppDataLocalAndroidsdkplatform-tools> 경로안에 adb 가들어있다. 그러므로 이 폴더 안으로 들어가서 아래 명령어를 실행한다.

(이작업은 handheld기기가 컴퓨터와 연결이 끊어지거나 android studio 가 새로 시작되면 매번 다시해야 하는 작업이다.)

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

Note: You must use the IP address You can use any available port on your development machine. Be sure you use the same port in both commands. (In this example the port is 4444.)

Host: connected
Target: connected

The watch is now connected to the debugger and you’re ready to start debugging.

When you debug a watch using Bluetooth, adb always uses the IP address plus the port that you assigned. Therefore, all adb commands use this format (continuing the example, the port is 4444):

adb -s <command> 

If you are not using the emulator and have only one device connected for debugging, you don’t need to specify the address at all:

adb <command>

mac os의 경우

Option 2 – Manually (just the platform tools)

This is the easiest way to get a manual installation of ADB and Fastboot.

Delete your old installation (optional)

rm -rf ~/.android-sdk-macosx/

Navigate to and click on the SDK Platform-Tools for Mac link.

Go to your Downloads folder

cd ~/Downloads/

Unzip the tools you downloaded

unzip platform-tools-latest*.zip 

Move them somewhere you won’t accidentally delete them

mkdir ~/.android-sdk-macosx
mv platform-tools/ ~/.android-sdk-macosx/platform-tools

Add platform-tools to your path

echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile

Refresh your bash profile (or restart your terminal app)

source ~/.bash_profile

Start using adb

adb devices

original source :

Creating Lists

Lists let users select an item from a set of choices easily on wearable devices.

The Wearable UI Library includes the WearableListView class .

To create a list in your Android Wear apps:

  1. Add a WearableListView element to your activity’s layout definition.
  2. Create a custom layout implementation for your list items.
  3. Use this implementation to create a layout definition file for your list items.
  4. Create an adapter to populate the list.
  5. Assign the adapter to the WearableListView element

Add a List View




Create a Layout Implementation for List Items

This layout also implements the methods in the WearableListView.OnCenterProximityListener interface to change the color of the item’s icon and fade the text in response to events from WearableListView as the user scrolls through the list.

public class WearableListItemLayout extends LinearLayout
            implements WearableListView.OnCenterProximityListener {

   private ImageView mCircle;
   private TextView mName;

   private final float mFadedTextAlpha;
   private final int mFadedCircleColor;
   private final int mChosenCircleColor;

   public WearableListItemLayout(Context context) {
       this(context, null);

   public WearableListItemLayout(Context context, AttributeSet attrs) {
       this(context, attrs, 0);

   public WearableListItemLayout(Context context, AttributeSet attrs,
                                 int defStyle) {
       super(context, attrs, defStyle);

       mFadedTextAlpha = getResources()
                        .getInteger(R.integer.action_text_faded_alpha) / 100f;
       mFadedCircleColor = getResources().getColor(R.color.grey);
       mChosenCircleColor = getResources().getColor(;

   // Get references to the icon and text in the item layout definition
   protected void onFinishInflate() {
       // These are defined in the layout file for list items
       // (see next section)
       mCircle = (ImageView) findViewById(;
       mName = (TextView) findViewById(;

   public void onCenterPosition(boolean animate) {
       ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);

   public void onNonCenterPosition(boolean animate) {
       ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);

Create a Layout Definition for Items



Create an Adapter to Populate the List

private static final class Adapter extends WearableListView.Adapter {
   private String[] mDataset;
   private final Context mContext;
   private final LayoutInflater mInflater;

   // Provide a suitable constructor (depends on the kind of dataset)
   public Adapter(Context context, String[] dataset) {
       mContext = context;
       mInflater = LayoutInflater.from(context);
       mDataset = dataset;

   // Provide a reference to the type of views you're using
   public static class ItemViewHolder extends WearableListView.ViewHolder {
       private TextView textView;
       public ItemViewHolder(View itemView) {
           // find the text view within the custom item's layout
           textView = (TextView) itemView.findViewById(;

   // Create new views for list items
   // (invoked by the WearableListView's layout manager)
   public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                         int viewType) {
       // Inflate our custom layout for list items
       return new ItemViewHolder(mInflater.inflate(R.layout.list_item, null));

   // Replace the contents of a list item
   // Instead of creating new views, the list tries to recycle existing ones
   // (invoked by the WearableListView's layout manager)
   public void onBindViewHolder(WearableListView.ViewHolder holder,
                                int position) {
       // retrieve the text view
       ItemViewHolder itemHolder = (ItemViewHolder) holder;
       TextView view = itemHolder.textView;
       // replace text contents
       // replace list item's metadata

   // Return the size of your dataset
   // (invoked by the WearableListView's layout manager)
   public int getItemCount() {
       return mDataset.length;

Associate the Adapter and Set a Click Listener

public class WearActivity extends Activity
                         implements WearableListView.ClickListener {

   // Sample dataset for the list
   String[] elements = { "List Item 1", "List Item 2", ... };

   protected void onCreate(Bundle savedInstanceState) {

       // Get the list component from the layout of the activity
       WearableListView listView =
           (WearableListView) findViewById(;

       // Assign an adapter to the list
       listView.setAdapter(new Adapter(this, elements));

       // Set a click listener

   // WearableListView click listener
   public void onClick(WearableListView.ViewHolder v) {
       Integer tag = (Integer) v.itemView.getTag();
       // use this data to complete some action ...

   public void onTopEmptyRegionClick() {

original source :

사용자로부터 음성으로 data입력을 받으려는 경우

Obtaining Free-form Speech Input

In addition to using voice actions to launch activities, you can also call the system’s built-in Speech Recognizer activity to obtain speech input from users. This is useful to obtain input from users and then process it, such as doing a search or sending it as a message.

In your app, you call


using the


action. This starts the speech recognition activity, and you can then handle the result in



private static final int SPEECH_REQUEST_CODE = 0;

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
   Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Start the activity, the intent will be populated with the speech text
   startActivityForResult(intent, SPEECH_REQUEST_CODE);

// This callback is invoked when the Speech Recognizer returns.
// This is where you process the intent and extract the speech text from the intent.
protected void onActivityResult(int requestCode, int resultCode,
       Intent data) {
   if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
       List<String> results = data.getStringArrayListExtra(
       String spokenText = results.get(0);
       // Do something with spokenText
   super.onActivityResult(requestCode, resultCode, data);

original source:

Adding Pages to a Notification

additional pages appear immediately to the right of the main notification card.

To create a notification with multiple pages:

  1. Create the main notification (the first page) with NotificationCompat.Builder, in the way you’d like the notification to appear on a handset.
  2. Create the additional pages for the wearable with NotificationCompat.Builder.
  3. Apply the pages to the main notification with the addPage() method or add multiple pages in a Collectionwith the addPages() method.

// Create builder for the main notification
NotificationCompat.Builder notificationBuilder =
       new NotificationCompat.Builder(this)
       .setContentTitle("Page 1")
       .setContentText("Short message")

// Create a big text style for the second page
BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
              .bigText("A lot of text...");

// Create second page notification
Notification secondPageNotification =
       new NotificationCompat.Builder(this)

// Extend the notification builder with the second page
Notification notification = notificationBuilder
       .extend(new NotificationCompat.WearableExtender()

// Issue the notification
notificationManager =
notificationManager.notify(notificationId, notification);

original source :

Receiving Voice Input in a Notification

If you have handheld notifications that include an action to input text, such as reply to an email, it should normally launch an activity on the handheld device to input the text. However, when your notification appears on a wearable, there is no keyboard input, so you can let users dictate a reply or provide pre-defined text messages using RemoteInput.

When users reply with voice or select one of the available messages, the system attaches the text response to the Intentyou specified for the notification action and sends that intent to your handheld app.

Define the Voice Input

To create an action that supports voice input, create an instance of


that you can add to your notification action. This class’s constructor accepts a string that the system uses as the key for the voice input, which you’ll later use to retrieve the text of the input in your handheld app.For example, here’s how to create a


object that provides a custom label for the voice input prompt:

// Key for the string that's delivered in the action's intent
private static final String EXTRA_VOICE_REPLY = "extra_voice_reply";

String replyLabel = getResources().getString(R.string.reply_label);

RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)

Add Pre-defined Text Responses



<?xml version="1.0" encoding="utf-8"?>
   <string-array name="reply_choices">
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
String replyLabel = getResources().getString(R.string.reply_label);
String[] replyChoices = getResources().getStringArray(R.array.reply_choices);

RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)

Add the Voice Input as a Notification Action

// Create an intent for the reply action
Intent replyIntent = new Intent(this, ReplyActivity.class);
PendingIntent replyPendingIntent =
       PendingIntent.getActivity(this, 0, replyIntent,

// Create the reply action and add the remote input
NotificationCompat.Action action =
       new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
               getString(R.string.label), replyPendingIntent)

// Build the notification and add the action via WearableExtender
Notification notification =
       new NotificationCompat.Builder(mContext)
               .extend(new WearableExtender().addAction(action))

// Issue the notification
NotificationManagerCompat notificationManager =
notificationManager.notify(notificationId, notification);

Receiving the Voice Input as a String

(notification은 sync와는 달리 일방통행이라고 하지만 reply action intent를 통해 reply message를 전달 받을수 있다. )

To receive the user’s transcribed message in the activity you declared in the reply action’s intent, call


, passing in the “Reply” action’s intent. This method returns a


that contains the text response. You can then query the


to obtain the response.


Do not use


to obtain the voice result, because the voice input is stored as


. The


method provides a convenient way to receive a character sequence without having to process the



* Obtain the intent that started this activity by calling
* Activity.getIntent() and pass it into this method to
* get the associated voice input string.

private CharSequence getMessageText(Intent intent) {
   Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
   if (remoteInput != null) {
       return remoteInput.getCharSequence(EXTRA_VOICE_REPLY);
   return null;