Scroll Essential Android 2.3 User Manual Page 31

  • Download
  • Add to my manuals
  • Print
  • Page
    / 47
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 30
Android Wear Docs, Release 1.1
}
// Data layer and lifecycle implementation (Step 2)
...
}
2. Add callback methods for the data layer and lifecycle events. For simplicity, send a message in the onConnected
callback method.
// Connect to the data layer when the Activity starts
@Override
protected void onStart() {
super.onStart();
googleClient.connect();
}
// Send a message when the data layer connection is successful.
@Override
public void onConnected(Bundle connectionHint) {
String message = "Hello wearable\n Via the data layer";
//Requires a new thread to avoid blocking the UI
new SendToDataLayerThread("/message_path", message).start();
}
// Disconnect from the data layer when the Activity stops
@Override
protected void onStop() {
if (null != googleClient && googleClient.isConnected()) {
googleClient.disconnect();
}
super.onStop();
}
// Placeholders for required connection callbacks
@Override
public void onConnectionSuspended(int cause) { }
@Override
public void onConnectionFailed(ConnectionResult connectionResult) { }
3. Define a class that extends the Thread class and implements a method that sends your message to all nodes
currently connected to the data layer. This task can block the main UI thread, so it must run in a new thread.
class SendToDataLayerThread extends Thread {
String path;
String message;
// Constructor to send a message to the data layer
SendToDataLayerThread(String p, String msg) {
path = p;
message = msg;
}
public void run() {
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await();
for (Node node : nodes.getNodes()) {
SendMessageResult result = Wearable.MessageApi.sendMessage(googleClient, node.getId(), path, message.getBytes()).await();
if (result.getStatus().isSuccess()) {
Log.v("myTag", "Message: {" + message + "} sent to: " + node.getDisplayName());
}
6.1. First Wearable Message 27
Page view 30
1 2 ... 26 27 28 29 30 31 32 33 34 35 36 ... 46 47

Comments to this Manuals

No comments

Sanyo Cadnica N-500AC podręczniki

Instrukcje obsługi i podręczniki użytkownika dla Akcesoria komunikacja Sanyo Cadnica N-500AC.
Dostarczamy 1 pdf podręczników Sanyo Cadnica N-500AC do pobrania za darmo według typów dokumentów: Instrukcja Użytkownika






Więcej produktów i instrukcji dla Akcesoria komunikacja Sanyo

Modele Rodzaj dokumentu
N-50AAAS Instrukcja Użytkownika   Sanyo N-50AAAS User Manual, 1 strony
N-2U Instrukcja Użytkownika   Sanyo N-2U User Manual, 1 strony
CP-1700SCR Instrukcja Użytkownika   Sanyo CP-1700SCR User Manual, 1 strony
Twicell HR-4/5SCU Instrukcja Użytkownika   Sanyo Twicell HR-4/5SCU User Manual, 1 strony
KR-600AE Instrukcja Użytkownika   Sanyo KR-600AE User Manual, 1 strony
Twicell HF-E5U Instrukcja Użytkownika   Sanyo Twicell HF-E5U User Manual, 1 strony
UF652436F Instrukcja Użytkownika   Sanyo UF652436F User Manual, 1 strony
Twicell HR-AU Instrukcja Użytkownika   Sanyo Twicell HR-AU User Manual, 1 strony
KR-1500AUL Instrukcja Użytkownika   Sanyo KR-1500AUL User Manual, 1 strony
KR-MH Instrukcja Użytkownika   Sanyo KR-MH User Manual, 1 strony
ML1220 Instrukcja Użytkownika   Sanyo ML1220 User Manual, 1 strony
Cadnica N-4U Instrukcja Użytkownika   Sanyo Cadnica N-4U User Manual, 1 strony
N-190N Instrukcja Użytkownika   Sanyo N-190N User Manual, 1 strony
KR-4400D Instrukcja Użytkownika   Sanyo KR-4400D User Manual, 1 strony
KR-1100AAU Instrukcja Użytkownika   Sanyo KR-1100AAU User Manual, 1 strony
ML2016 Instrukcja Użytkownika   Sanyo ML2016 User Manual, 1 strony
UF-2812 Instrukcja Użytkownika   Sanyo UF-2812 User Manual, 1 strony
N-250AAA Instrukcja Użytkownika   Sanyo N-250AAA User Manual, 1 strony