In my Android application, I have the following code:
BluetoothManager bluetoothManager = (BluetoothManager)Android.App.Application.Context.GetSystemService(Java.Lang.Class.FromType(typeof(BluetoothManager)));
_bluetoothGattServer = bluetoothManager.OpenGattServer(Android.App.Application.Context, _customBluetoothGattServerCallback);
// _bluetoothGattServer is always null now
Before it would work every time, but after a few changes in my app, OpenGattServer
always returns null now. The only difference that I think could be relevant is that before I was calling this code on a button-clicked event, but now I am calling this code on a different thread, invoked from a Timer
.
In case that it's because of a thread issue, is there a way to force this code to run on the UI thread? (or whatever appropriate thread)
Note: I'm writing this app in Xamarin.Android, but an answer in native Android would work for me.