Android BluetoothGatt:OnClient注册()-status=133//onConnectionStateChange状态:257
更新Cordova、Android和iOS平台后,应用程序不再连接,我也不明白为什么?Android studio中的Logcat不断重复关于蓝牙GATT的相同错误。我是noobish,所以除了谷歌搜索和提问之外,我真的不知道如何从这里调试 我尝试卸载、更新Gradle、更改wifi插件,但我认为这是蓝牙错误。但我的信念可能是错误的 Android studio中Logcat中的循环Android BluetoothGatt:OnClient注册()-status=133//onConnectionStateChange状态:257,android,bluetooth,raspberry-pi,bluetooth-gatt,Android,Bluetooth,Raspberry Pi,Bluetooth Gatt,更新Cordova、Android和iOS平台后,应用程序不再连接,我也不明白为什么?Android studio中的Logcat不断重复关于蓝牙GATT的相同错误。我是noobish,所以除了谷歌搜索和提问之外,我真的不知道如何从这里调试 我尝试卸载、更新Gradle、更改wifi插件,但我认为这是蓝牙错误。但我的信念可能是错误的 Android studio中Logcat中的循环 D/BluetoothAdapter: STATE_ON scan not started yet I/
D/BluetoothAdapter: STATE_ON
scan not started yet
I/@@@@@@: @@@ connect
I/@@@@@@: @@@ creating gatt handler
@@@ getRemoteDevice
@@@ connectGatt
D/BluetoothAdapter: STATE_ON
D/BluetoothGatt: connect() - device: B8:27:EB:C6:4F:19, auto: false
D/BluetoothAdapter: isSecureModeEnabled
D/BluetoothGatt: registerApp()
registerApp() - UUID=ae27921d-3fa8-45f4-bf37-b1d9abf04149
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/@@@@@@: @@@ onConnectionStateChange status: 257 newState: 0
@@@ connect error - status: 257
D/BluetoothAdapter: stopLeScan()
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: scan not started yet
I/@@@@@@: @@@ connect
I/@@@@@@: @@@ creating gatt handler
@@@ getRemoteDevice
@@@ connectGatt
D/BluetoothAdapter: STATE_ON
D/BluetoothGatt: connect() - device: B8:27:EB:C6:4F:19, auto: false
D/BluetoothAdapter: isSecureModeEnabled
D/BluetoothGatt: registerApp()
registerApp() - UUID=33e7344c-33e8-4366-8bd9-9336b80f4ce7
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/@@@@@@: @@@ onConnectionStateChange status: 257 newState: 0
@@@ connect error - status: 257
D/BluetoothAdapter: stopLeScan()
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: scan not started yet
这是抛出错误的函数
// Also maintains the per-device operation queue.
private class GattHandler extends BluetoothGattCallback
{
// Local copy of the key to BLE.mGatt. Fed by BLE.mNextGattHandle.
final int mHandle;
// The queue of operations.
LinkedList<Runnable> mOperations = new LinkedList<Runnable>();
// connect() and rssi() are handled separately from other operations.
CallbackContext mConnectContext;
CallbackContext mRssiContext;
CallbackContext mCurrentOpContext;
// Flag used when writing notification config descriptor.
// In this case we don't want to send back the result to JavaScript.
boolean mDontReportWriteDescriptor = false;
// The Android API connection.
BluetoothGatt mGatt;
// Maps of integer to Gatt subobject.
HashMap<Integer, BluetoothGattService> mServices;
HashMap<Integer, BluetoothGattCharacteristic> mCharacteristics;
HashMap<Integer, BluetoothGattDescriptor> mDescriptors;
// Monotonically incrementing key to the subobject maps.
int mNextHandle = 1;
// Notification callbacks. The BluetoothGattCharacteristic object, as found
// in the mCharacteristics map, is the key.
HashMap<BluetoothGattCharacteristic, CallbackContext> mNotifications =
new HashMap<BluetoothGattCharacteristic, CallbackContext>();
GattHandler(int h, CallbackContext cc)
{
mHandle = h;
mConnectContext = cc;
}
// Run the next operation, if any.
// TODO: Make another method processNext that sets mCurrentOpContext to
// null and calls process. That would clean up repeated code a bit.
// Also consider writing method that adds a runnable to the mOperations
// queue and calls process, this would also reduce some repeated code.
void process()
{
if (mCurrentOpContext != null) return;
Runnable runnable = mOperations.poll();
if (runnable == null) return;
runAction(runnable);
}
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
Log.i("@@@@@@", "@@@ onConnectionStateChange status: " + status + " newState: " + newState);
if (status == BluetoothGatt.GATT_SUCCESS)
{
try
{
JSONObject result = new JSONObject();
result.put("deviceHandle", mHandle);
result.put("state", newState);
Log.i("@@@@@@", "@@@ connect success");
keepCallback(mConnectContext, result);
}
catch(JSONException e)
{
Log.i("@@@@@@", "@@@ connect error: " + e);
e.printStackTrace();
mConnectContext.error("Connect error: " + e);
//assert(false);
}
}
else
{
// Could this be where we get 133? Yes it is.
Log.i("@@@@@@", "@@@ connect error - status: " + status);
mConnectContext.error(status);
}
}
//还维护每个设备的操作队列。
私有类GattHandler扩展了BluetoothGattCallback
{
//BLE.mnextgathandle提供的BLE.mGatt.密钥的本地副本。
最终int mHandle;
//操作队列。
LinkedList mOperations=新建LinkedList();
//connect()和rssi()与其他操作分开处理。
CallbackContext-mConnectContext;
CallbackContext-mRssiContext;
CallbackContext-mCurrentOpContext;
//写入通知配置描述符时使用的标志。
//在这种情况下,我们不希望将结果发送回JavaScript。
布尔值mDontReportWriteDescriptor=false;
//Android API连接。
蓝牙关贸总协定;
//整数到Gatt子对象的映射。
HashMap服务;
HashMap特征;
HashMap描述程序;
//子对象映射的单调递增键。
int mNextHandle=1;
//通知回调。找到的BluetoothGattCharacteristic对象
//在mCharacteristics地图中,是关键。
HashMap通知=
新的HashMap();
GattHandler(inth,CallbackContext cc)
{
mHandle=h;
mConnectContext=cc;
}
//运行下一个操作(如果有)。
//TODO:使另一个方法processNext将mCurrentOpContext设置为
//null并调用进程。这将稍微清理重复的代码。
//还考虑将操作添加到操作中的写入方法。
//在队列和调用过程中,这也会减少一些重复代码。
无效过程()
{
if(mCurrentOpContext!=null)返回;
Runnable=mOperations.poll();
if(runnable==null)返回;
运行操作(可运行);
}
@凌驾
连接状态更改的公共无效(蓝牙gatt gatt、int状态、int新闻状态)
{
Log.i(“@@@@@@@@”,“onConnectionStateChange状态:“+status+”newState:“+newState”);
如果(状态==蓝牙GATT.GATT\U成功)
{
尝试
{
JSONObject结果=新建JSONObject();
结果。放置(“设备句柄”,mHandle);
结果。put(“state”,newState);
Log.i(“@@@@@”,“连接成功”);
keepCallback(mConnectContext,result);
}
捕获(JSONException e)
{
Log.i(“@@@@@”,连接错误:“+e”);
e、 printStackTrace();
mConnectContext.error(“连接错误:+e”);
//断言(假);
}
}
其他的
{
//这可能是我们得到133的地方吗?是的。
Log.i(“@@@@@@”,“连接错误-状态:“+状态”);
mConnectContext.error(状态);
}
}
我想要一些关于如何解决这个问题或如何通过Android studio正确调试的面包屑或指导。
谢谢抛出此错误是因为我没有正确连接到wi-fi,并且在更新Cordova之前的代码以及iOS和Android平台工作正常。升级API级别时,我需要根据Cordova文档在AndroidManifest中更改Android:usesCleartextTraffic=true。这是一个很好的答案。。 文件:
我希望这对升级项目的人有所帮助。抛出此错误是因为我没有正确连接到wi-fi,更新Cordova之前的代码以及iOS和Android平台工作正常。升级时,我需要根据Cordova文档在AndroidManifest中更改Android:usesCleartextTraffic=trueAPI级别。这里有一个很好的答案。。 文件:
我希望这能帮助升级项目的人。我也有同样的问题(即,突然之间,手机上正常工作的代码不再存在,返回错误257)。但这不是Cordova实现。只是本机Java。我将尝试围绕您的发现进行调查,尽管不确定Wi-Fi为何会在蓝牙上产生问题。@MaurizioMacagno,是的,我会在您的平台中寻找一个更新,可能有新的安全措施或一个可能已更新并需要更改代码的插件。I有相同的问题(即,突然之间,手机上正常工作的代码不再存在,返回错误257)。但这不是Cordova实现。只是本机Java。我将尝试调查您的发现,尽管不确定为什么Wi-Fi会在蓝牙上产生问题。@MaurizioMacagno,是的,我会在您的平台中寻找一个更新,可能有新的安全措施或一个可能已更新并需要更改代码的插件。