在可穿戴模拟器的侦听服务的ondatachange中没有收到通过Data API从移动应用程序发送的数据。我可以发送通知,表示两者都已连接。我的代码,
DataAPI呼叫(移动)
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");
}
}
});
之后我收到“成功发送”的日志消息。
下面是穿着的ListenerService,
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);
}
}
}
和Android清单中的服务声明,
<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" />
没有在可穿戴模块中添加任何权限。建议。
答案 0 :(得分:1)
使用android:pathPattern=".*"
代替android:pathPrefix="*"