Android:蓝牙LE连接自动终止

时间:2016-02-10 21:38:42

标签: android bluetooth bluetooth-lowenergy

我正在测试两款Android设备之间的蓝牙LE连接(带有Android 6.0的Nexus 6和带有Android 5.1的三星Galaxy S6)。 Nexus设置为外围设备,三星连接为中心设备。始终正确建立连接,但几秒后连接关闭,没有任何明显的原因。这是GattServerCallback代码:

  public class MyServerCallBack extends BluetoothGattServerCallback
{


    @Override
    public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
        super.onConnectionStateChange(device, status, newState);


        if (newState == BluetoothProfile.STATE_CONNECTED) {


         Log.i(TAG,"SOMEONE CONNECTED TO OUR SERVER "+device.getName()+" "+device.getAddress());


        }

        else if (newState== BluetoothProfile.STATE_DISCONNECTED)
        {

            Log.i(TAG,"SOMEONE DISCONNECTED FROM OUR SERVER");
        }


    }

}

这是中央的BluetoothGattCallback:

公共类MyCallBack扩展了BluetoothGattCallback     {

    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        super.onConnectionStateChange(gatt, status, newState);

        if (status!=133)
        {

            if (newState == BluetoothProfile.STATE_CONNECTED) {


                if (mConnectionState!=STATE_CONNECTED)
                {

                    mConnectionState = STATE_CONNECTED;

                    }




            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {



                Log.i(TAG, "RECEIVED DISCONNECTED SIGNAL.");

            }

        }
        else
        {
            Log.e(TAG,"STATUS IS 133");
            //gatt.close();
            //gatt.connect();
            mConnectionState = STATE_DISCONNECTED;
            mDiscoveryState = STATE_IDLE;

        }

    }

建立连接几秒钟后。日志将指示断开连接,没有任何明显的原因。这是Android的已知错误吗?

0 个答案:

没有答案