【发布时间】:2015-02-09 10:42:06
【问题描述】:
我编写了一个 Android 应用程序 (4.4.2),它在大多数情况下都能正确连接/断开与 BLE 外围设备的连接。但是,每隔一段时间,我就会在 Bluetootgatt.java onClientConnectionState() 中收到关于 NullPointerException 的 LogCat 警告:
我的BluetoothGattCallback回调如下:
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED)
{
gatt.discoverServices(); // triggers onServicesDiscovered() callback
}
else if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_DISCONNECTED)
{
return;
}
else if (status != BluetoothGatt.GATT_SUCCESS)
{
gatt.disconnect();
}
}
应用程序在连接时总是正确地转到 onConnectionStateChange newState==STATE_CONNECTED 回调,但是当它抛出异常时(在应用程序断开连接时),它永远不会在 onConnectionStateChange 回调中进行任何地方。我在 2013 Nexus 7 上运行此程序。为什么会发生此异常?
【问题讨论】:
-
你成功了吗?