Scroll Essential Android 2.3 Bedienungsanleitung Seite 30

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 47
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 29
Android Wear Docs, Release 1.1
name, which is essential for the wearable data layer to work.
Data layer messages can originate from either a handheld or wearable. For bidirectional messaging both the handheld
and wearable should implement a message sender and listener.
6.1.1 Implement a Message Sender
This section describes how to send messages to the data layer. The example code shown sends messages from the
handheld to the data layer.
Add Build Dependencies
Add the following build dependencies to the build.gradle file (Module:mobile) in the Gradle Scripts folder, if necessary.
dependencies {
compile fileTree(dir: ’libs’, include: [’
*
.jar’])
compile ’com.android.support:appcompat-v7:21.0.+’
compile ’com.google.android.gms:play-services:6.5.+’
}
Add Metadata for Google Play Services
Add Google Play services metadata statement to the manifest of the sending device:
<application>
...
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Create the Message Sender
To send a message , update the code in the main Activity of the sending device. For the handheld, modify the code in
the mobile branch of the Android Studio project.
1. Build a Google Play Services client for the Wearable API.
public class MessageActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
GoogleApiClient googleClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_handheld);
// Build a new GoogleApiClient for the Wearable API
googleClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
26 Chapter 6. Data Layer Messages
Seitenansicht 29
1 2 ... 25 26 27 28 29 30 31 32 33 34 35 ... 46 47

Kommentare zu diesen Handbüchern

Keine Kommentare