Scan and List the Paired Bluetooth Devices

guru_vijayguru_vijay Member ✭✭
edited January 21 in Xamarin.iOS

Hello,
How to list out the paired Bluetooth devices programmatically in xamarin ios

Answers

  • Imran_619Imran_619 Member ✭✭✭

    Remember that Xamarin binds to native api so don't worry that something "relates to native ways"
    class btListener : Java.Lang.Object, IBluetoothProfileServiceListener
    {
    public void OnServiceConnected([GeneratedEnum] ProfileType profile, IBluetoothProfile proxy)
    {
    String deviceName = "JABRA WAVE+";

        BluetoothDevice result = null;
    
        var devices = BluetoothAdapter.DefaultAdapter.BondedDevices;
        if (devices != null)
        {
            foreach (BluetoothDevice device in devices)
            {
                if (deviceName == device.Name)
                {
                    result = device;
                    break;
                }
            }
        }
        var connect = Java.Lang.Class.FromType(typeof(BluetoothA2dp)).GetDeclaredMethod("connect", Java.Lang.Class.FromType(typeof(BluetoothDevice)));
        connect.Invoke((Java.Lang.Object)proxy, result);
    }
    
    public void OnServiceDisconnected([GeneratedEnum] ProfileType profile)
    {
    }
    

    }

    For more information on mobile app development you can visit https://www.arstudioz.com/mobile-app-development

Sign In or Register to comment.