Xamarin表单和蓝牙断开连接

Xamarin表单和蓝牙断开连接,xamarin,bluetooth,xamarin.android,xamarin.forms,Xamarin,Bluetooth,Xamarin.android,Xamarin.forms,是否存在设备断开连接时引发的Android.Bluetooth类事件?您必须设置add aBluetoothGattCallback public class MyGattCallback : BluetoothGattCallback { public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState) { base

是否存在设备断开连接时引发的Android.Bluetooth类事件?

您必须设置add a
BluetoothGattCallback

public class MyGattCallback : BluetoothGattCallback
{
    public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState)
    {
        base.OnConnectionStateChange(gatt, status, newState);

        if(newState == ProfileState.Disconnected)
        {
            // disconnected
        }
    }
}
当您连接设备时,您会传递:

BluetoothDevice device = ...;
var callback = new MyGattCallback();
device.ConnectGatt(Application.Context, false, callback);

嗨,谢谢你的回复。代码var callback=new BluetoothGattCallback();对吗?还是说var callback=newmygattcallback();?ThanksGatt是一个很有关联的东西。