Langsung ke konten

Paling sering dikunjungi

Terakhir dikunjungi


Accessing the Wearable Data Layer

On this page

  1. Using a minimal client

To call the Data Layer API, use the Wearable class to get instances of the various client classes, such as DataClient and MessageClient.

Refer to the following related resources:

Note: A Wear app can communicate with a phone app using the Data Layer API, but connecting to a network using this API is discouraged.

Using a minimal client

A minimal client, as shown in the following example, is enough to begin. See Accessing Google Play services APIs for additional information:

DataClient mDataClient = Wearable.getDataClient(context);

The context can be any valid Android context. If you are using the API within the scope of an Activity, use the getDataClient(activity) method of the Wearable class, which allows certain interactions to appear as dialogs rather than as notifications, e.g., if the user is asked to update their version of Google Play services.

By default, callbacks to listeners are made on the app's main UI thread. To have callbacks made on a different thread, use a WearableOptions object to specify a custom Looper (see WearableOptions.Builder):

WearableOptions options = new WearableOptions.Builder().setLooper(myLooper).build();
DataClient mDataClient = Wearable.getDataClient(context or activity, options);

Wearable API clients, such as DataClient and MessageClient, are inexpensive to create and don't need to be created only once and held onto. Use the style that suits your app. The client state, such as the set of registered listeners, is shared across all clients, and is preserved if Google Play services is updated while an app is running.

Situs ini menggunakan cookies untuk menyimpan preferensi Anda tentang bahasa di situs tertentu dan opsi tampilan.

Dapatkan berita dan tips terbaru dari developer Android yang akan membantu Anda mencapai kesuksesan di Google Play.

* Wajib Diisi


Ikuti Google Developers di WeChat

Buka situs ini dalam bahasa ?

Anda meminta halaman dalam bahasa , namun preferensi bahasa untuk situs ini adalah .

Ingin mengubah preferensi bahasa dan mengakses situs ini dalam bahasa ? Jika nanti Anda ingin mengubah preferensi bahasa, gunakan menu bahasa di bagian bawah setiap halaman.

Kelas ini memerlukan tingkat API atau yang lebih tinggi

Dokumen ini tersembunyi karena level API yang Anda pilih untuk dokumentasi ini adalah . Anda dapat mengubah level API dokumentasi dengan pemilih di atas menu navigasi sebelah kiri.

Untuk informasi lebih lanjut tentang menentukan level API yang diperlukan aplikasi Anda, baca Mendukung Versi Platform Yang Berbeda.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)