A Bluetooth headset connection problem

Code as follows:

IBluetoothProfileServiceListener profile = new ProfileListener() { device = device };
var result = adapter.GetProfileProxy(BaseContext, profile, ProfileType.Headset);

public class ProfileListener : IBluetoothProfileServiceListener
{
public void Dispose()
{

    }

    private BluetoothHeadset headset;
    public BluetoothDevice device;
    public IntPtr Handle { get; }

    public void OnServiceConnected(ProfileType profile, IBluetoothProfile proxy)
    {
        if (profile == ProfileType.Headset)
        {

            headset = (BluetoothHeadset)proxy;
            if (headset.GetConnectionState(device) != ProfileState.Connected)
            {
                try
                {

                    headset.Class.GetMethod("connect", Class.FromType(typeof(BluetoothDevice)))
                        .Invoke(headset, device);
                }
                catch (Exception e)
                {

                }

            }
        }
    }

    public void OnServiceDisconnected(ProfileType profile)
    {

    }
}

The GetProfileProxy method is executed after the return value is false

How should I do? This is the xamarin BUG?, because the same code is executed in the Android studio there is no problem.

Tagged:

Posts

Sign In or Register to comment.