Android 使用功能API检查时,节点计数始终为零
当我尝试在android wear emulator(应用程序安装:wear module)和android设备(应用程序安装:mobile module)之间共享数据时,我在发送消息之前使用capabilityAPI检查设置的节点数,结果似乎总是0。我的设备和wear emulator始终是连接的。事实上,我能够从设备到wear emulator发送通知。下面是代码(显然在服务函数中调用)Android 使用功能API检查时,节点计数始终为零,android,wear-os,android-wear-data-api,Android,Wear Os,Android Wear Data Api,当我尝试在android wear emulator(应用程序安装:wear module)和android设备(应用程序安装:mobile module)之间共享数据时,我在发送消息之前使用capabilityAPI检查设置的节点数,结果似乎总是0。我的设备和wear emulator始终是连接的。事实上,我能够从设备到wear emulator发送通知。下面是代码(显然在服务函数中调用) GoogleApiClient-GoogleApiClient=new-GoogleApiClient.
GoogleApiClient-GoogleApiClient=new-GoogleApiClient.Builder(此)
.addApi(可穿戴的.API)
.build();
ConnectionResult ConnectionResult=GoogleAppClient.blockingConnect(
Constants.GOOGLE\u API\u CLIENT\u TIMEOUT\u S,TimeUnit.SECONDS);
if(connectionResult.issucess()&&GoogleAppClient.isConnected()){
CapabilityApi.GetCapabilityResult结果=可穿戴。CapabilityApi.getCapability(
GoogleapClient,
“显示详细信息”,
能力过滤器(可到达)
.等待(10,时间单位秒);
if(result.getStatus().issucess()){
Set nodes=result.getCapability().getNodes();
用于(节点:节点){
Wearable.MessageApi.sendMessage(
GoogleAppClient,node.getId(),path,extraInfo.getBytes();
}
}否则{
Log.e(标记“startDeviceActivityInternal()无法获取功能,状态:”
+result.getStatus().getStatusMessage());
}
googleApiClient.disconnect();
}
我建议你
注意:我的两个模块包的名称是相同的。另外,任何关于功能名称如何工作的澄清都是很好的
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(
Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);
if (connectionResult.isSuccess() && googleApiClient.isConnected()) {
CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability(
googleApiClient,
"SHOW DETAILS",
CapabilityApi.FILTER_REACHABLE)
.await(10, TimeUnit.SECONDS);
if (result.getStatus().isSuccess()) {
Set<Node> nodes = result.getCapability().getNodes();
for (Node node : nodes) {
Wearable.MessageApi.sendMessage(
googleApiClient, node.getId(), path, extraInfo.getBytes());
}
} else {
Log.e(TAG, "startDeviceActivityInternal() Failed to get capabilities, status: "
+ result.getStatus().getStatusMessage());
}
googleApiClient.disconnect();
}