DataLayer


 

  1. DataLayer from Phone to Wear
  2. DataLayer from Wear to Phone
  3. Transferring Assets

 

About DataLayer:
object description
DataItem Sets up shared data storage between the devices with automatic syncing.
MessageApi Sends fire‐and‐forget‐type commands, such as controlling and starting an intent on the wearable from the handheld or controlling a phone app from the wearable. Delivers an error when the devices are disconnected or the message if they are connected.
Asset Sends binary blobs of data, such as images. Attached to data items, the system handles the transfer automatically. Minimizes Bluetooth bandwidth by caching large assets to avoid retransmission.
WearableListenerService (for services) Used with services. Listens to data layer events.
DataListener (for foreground activities) Used with foreground services. Listens to data layer events when the activity is in the foreground.
Channel You can use the ChannelApi class to transfer large data items, such as music and movie files, from a handheld to a wearable device. The Channel API for data transfer has the following benefits:

  • Transfer large data files between two or more connected devices, without the automatic synchronization provided when using Asset objects attached to DataItem objects.
  • Reliably send a file that is too large in size to send using the MessageApi class.
  • Transfer streamed data, such as music pulled from a network server or voice data from the microphone.

datalayer_info

 

1. DataLayer from Phone to Wear

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, select Wear & Mobile Module for this tutorial, create “Blank Activity” and click “Finish” button.

Mobile Module
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

Step 5 : Open build.gradle(Module: mobile) and add following code :

Wear Module
Step 6 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, ListenerService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

Step 6 : Open build.gradle(Module: app) and add following code :

ScreenShot:

datalayer3 datalayer datalayer2

Download SourceCode

 

 

2. DataLayer from Wear to Phone

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, select Wear & Mobile Module for this tutorial, create “Blank Activity” and click “Finish” button.

Mobile Module
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, ListenerService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

Step 6 : Open build.gradle(Module: app) and add following code :

Wear Module
Step 7 : Open res -> layout -> activity_main.xml and add following code :

Step 8 : Open src -> package -> MainActivity.java and add following code :

Step 9 : Open AndroidManifest.xml and add following code :

Step 7 : Open build.gradle(Module: app) and add following code :

ScreenShot:

datalayer from wear datalayer from wear2 datalayer from wear3

Download SourceCode

 

 

3. Transferring Assets

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, select Wear & Mobile Module for this tutorial, create “Blank Activity” and click “Finish” button.

Mobile Module
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

Step 7 : Open build.gradle(Module: app) and add following code :

Wear Module
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

Step 5 : Open build.gradle(Module: app) and add following code :

ScreenShot:

datalayer transfer asset2 datalayer transfer asset3 datalayer transfer asset datalayer transfer asset4

Download SourceCode