CapabilityApi不返回任何节点 [英] CapabilityApi does not return any Nodes

查看:161
本文介绍了CapabilityApi不返回任何节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在掌上电脑和可穿戴应用之间进行通信,我正在尝试使用 CapabilityApi 节点 C $ C>。我知道设备已连接 - 其他应用程序和示例工作正常 - 但是当我运行我的可穿戴应用程序时,既不会调用 getCapability() getAllCapabilities ()返回任何节点

I'm attempting to communicate between my handheld and wearable app and I am trying to find the correct Node by using the CapabilityApi. I know that the devices are connected - other apps and samples work just fine - but when I run my wearable app neither calls to getCapability() or getAllCapabilities() return any Nodes at all.

其他一切似乎都能正常工作 - 事实上,如果我使用 NodeApi 并且使用 MessageApi 发送消息,我可以找到手持设备就好了工作正常 - 但由于某些原因,每个设备的功能都没有公布。我已在res / values文件夹中正确设置了wear.xml,并确保两个应用程序在build.gradle中设置了相同的applicationId。

Everything else seems to work properly - in fact I can find the handheld device just fine if I use the NodeApi and sending messages with the MessageApi also seems to work properly - but the capabilities of each device are just not advertised for some reason. I have properly setup the wear.xml in the res/values folder and I made sure that both apps have the same applicationId set in the build.gradle.

我的可穿戴应用程序中的 CapabilityApi 如下所示:

The calls to the CapabilityApi in my wearable app look like this:

Wearable.CapabilityApi.getCapability(mGoogleApiClient, SOME_CAPABILITY, CapabilityApi.FILTER_REACHABLE)
        .setResultCallback(new ResultCallback<CapabilityApi.GetCapabilityResult>() {
            @Override
            public void onResult(CapabilityApi.GetCapabilityResult result) {
                if (!result.getStatus().isSuccess()) {
                    return;
                }

                final CapabilityInfo info = result.getCapability();
                updateCapabilities(info);
            }
        });

但是设置<节点> CapabilityInfo 实例总是空的!另外使用 Wearable.CapabilityApi.getAllCapabilities()总是返回一个空的列表<节点>

But the Set<Node> in the CapabilityInfo instance is always empty! Also using Wearable.CapabilityApi.getAllCapabilities() always returns an empty List<Node>!

为了记录,我的掌上电脑应用程序的wear.xml如下所示:

And for the record the wear.xml of my handheld app looks like this:

<resources>
    <string-array name="android_wear_capabilities">
        <item>some_capability</item>
    </string-array>
</resources>

我已经梳理了我的代码库,寻找错误,但我找不到它。没有任何意义,为什么不宣传这些功能。

I have combed through my codebase looking for an error but I just can't find it. It doesn't make any sense why the capabilities are not advertised.

推荐答案

简答:



对两者使用相同的调试证书掌上电脑和可穿戴应用程序,否则 CapabilityApi 将无效。

错误结果非常简单!修复它只需要编辑build.gradle中的signingConfig。

The error turned out to be pretty simple! Fixing it just involves editing the signingConfig in the build.gradle.

我使用通用调试证书来签署掌上电脑应用程序的调试版本:

I was using a common debug certificate for signing the debug builds of my handheld app:

signingConfigs {
    debug {
        storeFile file("debug.jks")
        storePassword ...
        keyAlias ...
        keyPassword ...
    }
}

buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        ...
    }
}

但我的可穿戴应用程序没有使用相同的调试证书,它显然使用了我的IDE提供的默认调试证书。似乎当手持和可穿戴应用程序没有使用相同的证书时 - 即使它只是一个调试版本 - 那么另一个应用程序无法找到设备的功能。这实际上很有意义,是什么让整个事情变得混乱,其他一切看起来都很好,因此很难确定这样的问题很难。

But my wearable app was not using that same debug certificate, it was apparently using the default debug certificate supplied by my IDE. It seems that when the handheld and wearable app are not using the same certificate - even when it is just a debug build - then the capabilities of a device cannot be found by the other one. Which makes a lot of sense actually, what makes this whole thing confusing is that everything else seems to work just fine and as such pinpointing a problem like this is difficult.

In我的情况下,我从掌上电脑应用程序的build.gradle中删除了常见的调试配置,并且 CapabilityApi 立即开始工作。我认为为可穿戴设备和掌上电脑应用程序设置相同的debug signingConfig也可以解决问题,但我现在没有测试。

In my case I removed the common debug singing config from the build.gradle of my handheld app and the CapabilityApi started working immediately. I think setting the same debug signingConfig for the wearable and handheld app would also fix the problem but I didn't test that for now.

这篇关于CapabilityApi不返回任何节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆