Wearable.getCapabilityClient在搜索功能时始终返回null。即使我遵循开发人员指南并且将wear.xml放在正确的位置,也可能无法正确找到它。
https://developer.android.com/training/wearables/data-layer/messages.html
AsyncTask.execute(() -> {
CapabilityInfo capabilityInfo;
capabilityInfo = Tasks.await(
Wearable.getCapabilityClient(getBaseContext()).getCapability("setqueue", CapabilityClient.FILTER_REACHABLE));
//Returns no nodes
});
wear.xml的结构 移动 - > Res - >值 - > wear.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="android_wear_capabilities">
<item>setqueue</item>
</string-array>
我不知道为什么它找不到这种能力,任何帮助都会受到赞赏。
答案 0 :(得分:0)
试试这个
private void showNodes() {
Task<CapabilityInfo> capabilitiesTask =
Wearable.getCapabilityClient(this)
.getCapability(Keys.APP_CAPABILITY, CapabilityClient.FILTER_REACHABLE);
capabilitiesTask.addOnSuccessListener(new OnSuccessListener<CapabilityInfo>() {
@Override
public void onSuccess(CapabilityInfo capabilityInfo) {
for (Node node : capabilityInfo.getNodes()) {
if (node.isNearby()) {
//Do something
break;
}
}
}
});
}