Alex K
Alex K

Reputation: 103

Getting Bluetooth Adapter working with Xamarin for Android API 19 or above

I am trying my first android project, but having trouble getting the BluetoothAdapter working. I am using Xamarin in Visual Studio with a nexus 5 emulator running Android 4.4 (API 19).

I tried the following code

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter; 
bluetoothAdapter.Enable();

And got an error message

System.NullReferenceException: Object reference not set to an instance of an > object

I also tried

BluetoothAdapter bluetoothAdapter = (BluetoothAdapter)this.GetSystemService(Context.BluetoothService);
bluetoothAdapter.Enable();

and again got an error

System.InvalidCastException: Specified cast is not valid.

This may be a very basic question, but it seems some of the support is outdated since as of Android 4.3 the bluetooth adapter is created in a new way.

Thanks!

Alex

Upvotes: 0

Views: 1537

Answers (1)

dev connectauto
dev connectauto

Reputation: 26

Bluetooh is not supported by the Android emulator, be it the Android SDK one or the Visual Studio Android emulator. It is so specified in the documentation.

Have a look here: https://developer.android.com/studio/run/emulator.html#about

Upvotes: 1

Related Questions