Scroll Essential Android 2.3 Manual de usuario Pagina 26

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 47
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 25
Android Wear Docs, Release 1.1
5.3 Handheld Activation
A great way to start your wearable app is from a notification on the wearable. This is useful when you already have a
handheld app and want to extend features to a wearable. The handheld app starts the launch process by sending a data
object to the wearable that contains the information the wearable needs to post a notification locally. Users swipe this
notification and tap the Open icon to launch the wearable portion of your app. They return to the notification stream
when the wearable app closes.
Often times you want to launch the wearable app with extra data that tells it what feature to open or what data to
display. For example, a general handheld golf app might open the wearable for a specific golf course. This section
includes details about adding such data to the launch process. Without this, the wearable app simply launches in its
default mode.
5.3.1 Prerequisite
This procedure relies on communication through the data layer. Communication through the data layer requires setup
of Google Play Services for wearables in both the handheld and wearable devices (see Data Layer DataMap Objects).
5.3.2 Post a Notification
1. First create a DataMap object that includes the title and body for the notification. Optionally, include any extra
data that you want to pass to your wearable app when it starts. Then send this DataMap object to the wearable
data layer, along with a path constant that identifies the purpose of the data. The SendToDataLayerThread class
in this example is defined in Data Layer DataMap Objects.
String WEARABLE_START_PATH = "/wearable_start";
// Create a DataMap
DataMap notifyWearable = new DataMap();
notifyWearable.putString("title", "Notification Title");
notifyWearable.putString("body", "Start now?");
// Optional extra data to use when starting wearable
notifyWearable.putString("extra", "extra data")
// Send to data layer
new SendToDataLayerThread(WEARABLE_START_PATH, notifyWearable).start();
2. In the wearable, receive the DataMap in a WearableListenerService class. The following excerpt shows a sample
override for the onDataChanged method of the service.
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
DataMap dataMap;
22 Chapter 5. Wearable Application Launch
Vista de pagina 25
1 2 ... 21 22 23 24 25 26 27 28 29 30 31 ... 46 47

Comentarios a estos manuales

Sin comentarios