Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CapabilityApi does not return any Nodes

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.

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.

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);
            }
        });

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

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.

like image 503
Xaver Kapeller Avatar asked Sep 06 '25 11:09

Xaver Kapeller


2 Answers

Short answer:

Use the same debug certificate for both the handheld and wearable app, otherwise the CapabilityApi won't work.


Long Answer:

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 {
        ...
    }
}

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 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.

like image 116
Xaver Kapeller Avatar answered Sep 08 '25 12:09

Xaver Kapeller


Check if:

  • ApplicationId in build.gradle for both modules is the same
  • The package name for both modules is the same
like image 23
saj Avatar answered Sep 08 '25 12:09

saj