This is a library that pairs with SensorDataTransporterWearable to achieve a connection between an Android Mobile Device
with the SmartWatch Device
Initialize the helper
val sensorDataTransporter = SensorDataTransporterHandheld(applicationContext)
sensorDataTransporter.smartWatchInit()
boolean: true -> Starts the smartwatch sensor and start receiving.
boolean: false -> Stops the smartwatch sensor.
sensorDataTransporter.startStopAccelerometer(boolean)
sensorDataTransporter.startStopGyroscope(boolean)
sensorDataTransporter.startStopHeartRate(boolean)
It just triggers the smartwatch to send the current step count.
sensorDataTransporter.stepCountSmartWatch
sensorDataTransporterHandheld.sensorListener =
object : SensorDataTransporterHandheld.SensorListener {
override fun onData(xyz: XYZ?, dataType: Int) {
if (dataType == SensorReceiver.DATA_TYPE_ACCELEROMETER) {
// Do something with the xyz object
} else {
// Do something with the xyz object
}
}
}
sensorDataTransporterHandheld.sensorListenerHeartRate =
object : SensorDataTransporterHandheld.SensorListenerHeartRate {
override fun onData(heartRate: Double) {
// Do something with the hearRate value.
}
}
sensorDataTransporterHandheld.stepCounterDataListener =
object : SensorDataTransporterHandheld.StepCounterDataListener {
override fun onData(steps: Int) {
// Do something with the steps value.
}
}
sensorDataTransporterHandheld.isWatchConnected(object :
SensorDataTransporterHandheld.isOkCallbackWatch {
override fun OK(displayName: String?) {
// Do something with the displaName value
}
override fun notOK() {
// Inform user that the device is not connected with the smartwatch
}
})
-
The
handheld
app and thesmartwatch
app must have the samepackage
name and must be signed with the samekeystore
-
You have to add this service inside
<application> .. </application>
tag
<service
android:name="com.damnluck.sensordatatransporterhandheld.smartwatch.SensorReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/dataAccelerometer" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/dataGyroscope" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/heartrateData" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/stepCount" />
</intent-filter>
</service>
- You have to add permissions in manifest
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
- Also, you have add important dependencies in your gradle file
implementation 'com.google.android.gms:play-services-fitness:18.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.gms:play-services-wearable:15.0.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'com.google.code.gson:gson:2.8.6'
Now the app is ready to receive messages from the handheld to start sending sensor data.