Connect to paired bluetooth device from Xamarin on Android

We need our application to be able to connect to a paired bluetooth device automatically when an application starts via A2DP or Hands Free Profile.

We are working in Xamarin (monodroid), for Android platform.

  • Picasso library stopped working today with facebook graph picture links
  • Download and Extract Zip File in Android
  • Adjusting size of custom dialog box in android
  • How to import slidingmenu on Android Studio?
  • Centering the TextView's text vertically in relation to its drawableLeft image
  • ActionBarActivity back button not popping from backstack
  • I’ve found this stackoverflow question: Programmatically connect to paired Bluetooth device

    But it relates to native ways of achieving this (see answer by kcoppock). I’d like to know if there is a way to achieve this via Xamarin. We can connect to SPP endpoint since it’s an RFCOMM based connection, but we need that and the audio connection, so we are loking for a way to connect to A2DP.

    Update 1:

    We have tried to connect using CreateInsecureRfcommSocketToServiceRecord method like this:

    mmSocket = device.CreateInsecureRfcommSocketToServiceRecord(0000110A-0000-1000-8000-00805F9B34FB);

    Upon a call to Connect, we are getting an error:

    read failed, socket might closed or timeout, read ret: -1

    Stack trace begins with:

    Java.IO.IOException at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod) [0x00062] in /Users/buil…

    Update 2:

    By the way, whene we try to connect via the native java test app using the approach by kcoppock, the connection code seems to work without an error, although the device isn’t being connected as an A2DP headset.

    The only programming way we have seen to be able to do it was this Google Play app, which proves that it is possible.

    Related posts:

    How do I create an ImageView in java code, within an existing Layout?
    Trouble importing into Eclipse
    React Native - java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in t...
    How to detect system information like os or device type
    R.string.value Help android notification
    Eclipse freeze accessing project -> properties -> android tab
  • How to open a pdf stored either in res/raw or assets folder?
  • Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android
  • Tinder app animation (Drag and Drop of view or layout ) in Android
  • Kivy for Android apps
  • How can I set up custom namespaces in layout file in Android studio?
  • Are Android View id supposed to be unique?
  • 3 Solutions collect form web for “Connect to paired bluetooth device from Xamarin on Android”

    Remember that Xamarin binds to native api so don’t worry that something “relates to native ways” 😉 Based on the anwser You referenced I wrote and tested the code below. I hope it will help You.

    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;
            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)

    Following code in e.g. OnCreate function:

    btListener btReceiver = new btListener();
    BluetoothAdapter.DefaultAdapter.GetProfileProxy(this, btReceiver, ProfileType.A2dp);

    Just looked at the date.. but I’m posting answer anyway – maybe it’s still going to help somebody

    You may check this blog post. adapter.BondedDevices property in this link will return a list of paired devices.

    There is a native java sample program and its analog in the Xamarin examples at :

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.