Pebble手表具有在Pebble连接/断开时全局发送的Intent。这可以让手机应用知道手表是否连接。 我已搜索,但我无法找到有关Android Wear类似功能的信息。 如何知道可穿戴设备是否连接到手机?是否有可能收到像Pebble一样的活动? 感谢检测可穿戴式连接/从Android手机断开连接
5
A
回答
3
您可以通过扩展WearableListenerService并重写onConnectedNodes()方法轻松地完成此操作。
穿戴式侧
public class DisconnectListenerService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks {
/* the capability that the phone app would provide */
private static final String CONNECTION_STATUS_CAPABILITY_NAME = "is_connection_lost";
private GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.build();
}
@Override
public void onConnectedNodes(List<Node> connectedNodes) {
if (mGoogleApiClient.isConnected()) {
updateStatus();
} else if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
private void updateStatus() {
Wearable.CapabilityApi.getCapability(
mGoogleApiClient, CONNECTION_STATUS_CAPABILITY_NAME,
CapabilityApi.FILTER_REACHABLE).setResultCallback(
new ResultCallback<CapabilityApi.GetCapabilityResult>() {
@Override
public void onResult(CapabilityApi.GetCapabilityResult result) {
if (result.getStatus().isSuccess()) {
updateConnectionCapability(result.getCapability());
} else {
Log.e(TAG, "Failed to get capabilities, " + "status: " + result.getStatus().getStatusMessage());
}
}
});
}
private void updateConnectionCapability(CapabilityInfo capabilityInfo) {
Set<Node> connectedNodes = capabilityInfo.getNodes();
if (connectedNodes.isEmpty()) {
// The connection is lost !
} else {
for (Node node : connectedNodes) {
if (node.isNearby()) {
// The connection is OK !
}
}
}
}
@Override
public void onConnected(Bundle bundle) {
updateStatus();
}
@Override
public void onConnectionSuspended(int cause) {
}
@Override
public void onDestroy() {
if (mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting()) {
mGoogleApiClient.disconnect();
}
super.onDestroy();
}
}
手机端
创造价值/目录下的xml文件名为wear.xml
<resources>
<string-array name="android_wear_capabilities">
<item>is_connection_lost</item>
</string-array>
</resources>
有关详细信息,签在我的解决办法这Stack Overflow Question
5
你试过NodeApi,您可以使用getConnectedNodes
获取节点的列表,以这台设备是当前连接。
或addListener(GoogleApiClient client, NodeApi.NodeListener listener)
其中
注册的监听器接收所有节点的事件。
那么作为阿克说,你可以得到它连接到电话设备,但要知道,你可以使用回调从NodeApi.NodeListener
onPeerConnected(Node peer) and onPeerDisconnected(Node peer)
+1
但是可以连接多个节点... – powder366 2015-07-18 15:03:10
4
是否穿戴式目前手持
List<Node> connectedNodes =
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await().getNodes();
连接
该列表包含这样的数据:
Node{Moto 360 6BBF, id=3b6d19bf, hops=1, isNearby=true}
相关问题
- 1. 检测连接/断开的android穿戴装置
- 2. 穿戴式蓝牙连接
- 3. 我可以从我的Android手机连接到连接到我的PC的可穿戴手表吗?
- 4. 如何检测戴/手持Android设备是否断开连接或使用回调连接?
- 5. QSqlDatabase断开连接检测
- 6. 检测NFC断开连接
- 7. 检测jsch断开连接
- 8. socket.io断开连接事件,客户端断开连接检测
- 9. TCP连接断开检测(如果中间连接断开)?
- 10. Tizen从可穿戴的数据发送到Android手机,也从手机到穿戴式
- 11. 在手机浏览器上的穿戴式打开链接
- 12. Android 2.1检测蓝牙音频连接/断开连接
- 13. 检测套接字断开连接
- 14. 多路连接随机断开连接
- 15. 检测eventmachine断开连接并测试重新连接
- 16. Google+ Android PlusClient连接/断开连接
- 17. 如何检测网络断开连接?
- 18. 检测断开持久卷曲连接
- 19. 检测STM32L442 USB断开连接
- 20. 如何检测erl_call断开连接
- 21. Xamarin.Android检测摄像头断开连接
- 22. 检测插座中的断开连接
- 23. Socket.io检测断开连接原因
- 24. 检测断开连接Winsock C++
- 25. 在Delphi中检测TCP连接/断开连接
- 26. 在C#中检测网络状态(连接 - 断开连接)
- 27. 检测USB连接/断开连接而不通过轮询GetMessage()
- 28. Android BLE GATT断开连接与设备断开连接
- 29. Android穿戴预览不连接到Wear模拟器
- 30. iPhone/iOS - 从蓝牙耳机连接和断开连接
这不是对问题的回答...应该标记 – 2016-01-01 12:14:33