附近的连接2.0中的错误代码 [英] Error codes in Nearby Connections 2.0

查看:80
本文介绍了附近的连接2.0中的错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试新的 Android附近的连接v2.0 API.现在,我的大多数设备都可以在大多数时间互相通话,但是我也得到了很多

I've been experimenting with the new Android Nearby Connections v2.0 API. Most of my devices can now talk to each other most of the time, but I also get a lot of error codes back when trying to connect. Checking status.getStatusCode() inside my program, I can see the following return codes:

  • STATUS_ALREADY_CONNECTED_TO_ENDPOINT(8003)
  • STATUS_BLUETOOTH_ERROR(8007)
  • STATUS_ENDPOINT_IO_ERROR(8012)
  • STATUS_ERROR(13)

我很难理解这些.第一个错误代码似乎不言自明,除了在未使用所谓的连接两侧的成功"返回代码打onConnectionResult回调的情况下,我会看到它.我当前的代码充满了trace语句,如果已经到达这些回调,我会看到日志记录条目.因此,也许设备之间的连接处于较低的级别,但是如果是这样,那么较高级别的代码就不会总是听到它的声音.

I'm having a hard time making sense of these. The first error code seems self-explanatory, except that I see it in cases when I haven't hit the onConnectionResult callback with a "SUCCESS" return code on either side of the alleged connection. My current code is full of trace statements, and I'd see logging entries if those callbacks had been reached. So maybe the devices are connected at some lower level, but if so, the higher-level code doesn't always hear about it.

我猜想STATUS_BLUETOOTH_ERROR指示记录日志的一侧出现蓝牙错误,而STATUS_ENDPOINT_IO_ERROR指示另一端出现错误(可能涉及蓝牙)吗?是否有可能获得更多详细信息? 我不时看到的STATUS_ERROR(13)状态听起来像是程序员为那些"WTF,我们永远都不会到达这里"而使用的错误代码,但是如果无法访问源代码,我只能猜测.

I'm guessing that STATUS_BLUETOOTH_ERROR indicates a Bluetooth error on the side that logs it, while STATUS_ENDPOINT_IO_ERROR indicates an error (probably involving Bluetooth) on the other end? Is it possible to get any more details? The STATUS_ERROR (13) status that I see once in a while sounds like the sort of error code a programmer would use for those "WTF, we should never get here" moments, but without access to the source code, I can only guess.

请注意,我发现在使用相同代码的其他时间彼此交谈的设备之间存在这些错误.有时,如果代码重试次数足够多,则最终会获得稳定的连接.有时它会连接,并立即与另一端断开连接.有时我会收到无尽的重复错误消息(STATUS_BLUETOOTH_ERROR和/或STATUS_ENDPOINT_IO_ERROR).

Note that I see these errors between devices that talk to each other beautifully at other times, using the same code. Sometimes if the code retries enough times, it eventually gets a stable connection. Sometimes it connects and gets instantly disconnected from the other end. Sometimes I just get an endless stream of repeated error messages (STATUS_BLUETOOTH_ERROR and/or STATUS_ENDPOINT_IO_ERROR).

我正在使用附近连接和连接策略P2P_CLUSTER.当双方都做广告和发现时,这些问题似乎最经常发生.但是,我写了两个专门研究广告或发现的较小程序,它们有时也会出现这些错误(但不经常出现).

I'm using Nearby Connections with the connection strategy P2P_CLUSTER. These problems seem to happen most often when both sides do both advertising and discovery. However, I wrote two smaller programs that specialize in either advertising or discovery, and they sometimes get these errors too (but less often).

在跟踪消息中,我还注意到来自附近连接的许多警告消息如下:

In the trace messages, I've also noticed lots of warning messages from Nearby Connections that look like this:

09-04 22:54:40.070 3866-3924/? W/NearbyConnections: Cannot deserialize BluetoothDeviceName: expecting min 16 raw bytes, got 6

我猜这是因为附近的连接"使用了自己的短令牌(例如ZGbx)而不是设备的蓝牙名称?不过,我完全不确定.而且无论如何,如果这些是附近连接"自己的特殊令牌,那么为什么会发出有关它的警告消息?

I'm guessing that this is because Nearby Connections uses its own short tokens (like ZGbx) instead of the device Bluetooth name? I'm not at all sure about that, though. And anyway, if these are Nearby Connections' own special tokens, then why would it be issuing warning messages about it?

推荐答案

[免责声明:我正在附近的连接上工作]我可以尝试帮助.

[Disclaimer: I work on Nearby Connections] I can try and help out.

STATUS_ALREADY_CONNECTED_TO_ENDPOINT:如果在与给定端点有任何挂起(onConnectionInitiated)或已建立(onConnectionResult)连接的同时调用"requestConnection",则会发生这种情况.将您的日志语句移到onConnectionInitiated之前,您应该知道为什么会引发此错误.

STATUS_ALREADY_CONNECTED_TO_ENDPOINT: This occurs if you call 'requestConnection' while you have any pending (onConnectionInitiated) or established (onConnectionResult) connections to the given endpoint. Move your log statements earlier, to onConnectionInitiated, and you should see why we throw this error.

STATUS_BLUETOOTH_ERROR:蓝牙出现问题.手机可能处于不良状态. (希望)这种情况不应该经常发生.但是,如果您确实要解决问题,请停止投放广告和重新尝试requestConnection之前进行发现.当检测到此错误时,附近的连接"将切换蓝牙,但前提是没有其他情况.

STATUS_BLUETOOTH_ERROR: Something went wrong with Bluetooth. The phone is probably in a bad state. This (hopefully) shouldn't happen too often. But if you really want a fix, stop advertising & discovery before reattempting requestConnection. Nearby Connections will toggle Bluetooth when it detects this error, but only if nothing else is going on.

STATUS_ENDPOINT_IO_ERROR:我们失去了与另一台设备的连接.发生这种情况的原因可能多种多样(它们可能走得太远,蓝牙不稳定,设备停止响应等).如果发现有连接时,请避免这种情况.发现可能很难在电话上进行,并且最多会减少带宽,最坏时会导致连接断开.

STATUS_ENDPOINT_IO_ERROR: We lost connection to the other device. This can happen for a variety of reasons (they could have walked too far away, Bluetooth was flaky, the device stopped responding, etc). If you're discovering while you have connections, avoid that. Discovery can be hard on the phone and reduces bandwidth at best, causes dropped connections at worst.

STATUS_ERROR:发生了某些错误,该错误不适用于其他错误代码.这是万能的.这通常是在onConnectionResult(FAILED)中返回的,以通知您onConnectionInitiated和等待双方接受连接之间出了问题.

STATUS_ERROR: Something went wrong that didn't fit well in the other error codes. It's a catch-all. This is most-often returned in onConnectionResult(FAILED), to notify you that something went wrong in between onConnectionInitiated and waiting for both sides to accept the connection.

在即将发布的版本中,我们还降低了无法反序列化BluetoothDeviceName"的日志严重性,因为这并不是真正的警告.就像你说的在发现时看到非附近的连接设备时的预期行为.

We've also lowered the log severity of "Cannot deserialize BluetoothDeviceName" in an upcoming release, since it's not really a warning. It's like you said; expected behavior when we see non-Nearby Connections devices while discovering.

如果您继续发现问题,请告诉我们您正在使用什么设备,我们将确保将它们添加到我们的测试套件中.

If you continue to see problems, let us know what devices you're using and we'll be sure to add them to our test suite.

这篇关于附近的连接2.0中的错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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