Data sent through Data API from mobile app is not received in ondatachange of listenerservice in wearable emulator.I can send a notification though, which indicates both are connected.Below my code,
DataAPI call (mobile)
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(SharedConstants.START_FREE_RUN);
putDataMapRequest.getDataMap().putString(SharedConstants.PROGRAM_TYPE,totalCountUpTimer);
PutDataRequest request = putDataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(mGoogleApiClient, request)
.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
if (!dataItemResult.getStatus().isSuccess()) {
Log.e(TAG, "buildWatchOnlyNotification(): Failed to set the data, "
+ "status: " + dataItemResult.getStatus().getStatusCode());
} else {
Log.d(TAG,"SuccessFully sent notification");
}
}
});
After which I am getting "successfully sent" log message.
Below is ListenerService in wear,
public class ListenerService extends WearableListenerService {
private static final String TAG = ListenerService.class.getSimpleName();
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
super.onDataChanged(dataEvents);
Log.d(TAG, "dchanged" + dataEvents);
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.v(TAG, "onMessageReceivedWear: " + messageEvent);
if (SharedConstants.START_FREE_RUN.equals(messageEvent.getPath())) {
// Request for this device open the attraction detail screen
// to a specific tourist attraction
String Distance = new String(messageEvent.getData());
Log.d("ListenerService",Distance);
}
}
}
and my service declaration in Android manifest,
<service android:name=".services.ListenerService">
<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="*" />
</intent-filter>
</service>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Did not add any permissions in wearable module.Do suggest.
使用android:pathPattern=".*"
代替android:pathPrefix="*"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.