禁用/启用连接时,不会在手持设备和可穿戴设备上触发onCapabilityChanged

时间:2017-07-09 21:50:11

标签: android wear-os

<service android:name=".SMessage">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
            <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
            <data android:host="*" android:pathPrefix="/send-message" android:scheme="wear" />
        </intent-filter>
    </service>


public class SMessage extends WearableListenerService {

@Override
        public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
        super.onCapabilityChanged(capabilityInfo);
        _A.toast("onCapabilityChanged");
        Set<Node> connectedNodes = capabilityInfo.getNodes();
        pickBestNodeId(connectedNodes);
    }
}

如果启用飞行器模式或禁用蓝牙连接,则不会触发此方法onCapabilityChanged

我错过了什么? _A.toast使用Application类显示吐司。

发送消息有效。!

1 个答案:

答案 0 :(得分:1)

您需要添加<intent-filter> <action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" /> <data android:host="*" android:scheme="wear" android:path="/com.mypackagename.my_capability_name"/> </intent-filter> 元素,以识别您正在侦听的(完全合格)功能:

my_capability_name

在其他设备上运行的应用的wear.xml中定义了<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="android_wear_capabilities"> <item>my_capability_name</item> </string-array> </resources>

select t.product_id, sum(cnt) as total,
       group_concat(issue, ':', cnt separator ',') as issues
from (select t.product_id, t.issue, count(*) as cnt
      from tickets t
      group by t.product_id, t.issue
     ) tp
group by t.product_id;

https://developer.android.com/training/wearables/data-layer/messages.html#AdvertiseCapabilities所述。

但有几点需要注意: