GMS Library Wrapper for Android Wear
This library demonstrates how to use Android Wearable GMS API for messaging and syncing data between mobile and wearable apps.
Features:
- Support latest Google Play Services (Wearable) 9.8.0
- Send and receive messages from both wear and mobile devices
- Syncing data between wearable and handhelds
- gradele:
dependencies {
compile 'com.cscao.libs:gmswear:0.97.4'
}
- Configure capabilities for your Application(or Activities)
see sample at
mobile/src/main/res/values/wear.xml
or you can add capabilities during runtime, see the commented MSG_CAPABILITY in mobile/src/main/java/com/cscao/apps/gmswear/PhoneActivity.java
- Configure GMS service in
AndroidManifest.xmlput below info insideapplicationtag
<service android:name="com.cscao.libs.gmswear.GmsWearService">
<intent-filter>
<!-- listeners receive events that match the action and data filters -->
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
<action android:name="com.google.android.gms.wearable.CHANNEL_EVENT" />
<data
android:host="*"
android:pathPrefix="/com.cscao.libs.gmswear/"
android:scheme="wear" />
</intent-filter>
</service>
note that you can customize pathPrefix and android:pathPrefix is optional.
-
Initialize the GmsWear in your application by calling
GmsWear.initialize(getApplicationContext());inonCreate(). see sample atmobile/src/main/java/com/cscao/apps/gmswear/PhoneApplication.java -
Call
GmsWear.getInstance()where you want to send msg/data -
Set a
DataConsumerwhere you want to receive msg/data, note that you need to register/unregister(often inonResumeandonPause()) your data consumer to the GmsWear instance.
You can also skip step 1 and dynamically add capabilities(either during initialization or right before you send data) to your app
More usage see the demo(either PhoneActivity.java or WearActivity.java) in this repo, and see the googlesamples (link below) although there are small api changes
This library is heavily inspired by the WCL library