android - OpenGattServer 返回 null
问题描述
在我的 Android 应用程序中,我有以下代码:
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
在它每次都可以工作之前,但是在我的应用程序中进行了一些更改之后,OpenGattServer
现在总是返回 null。我认为可能相关的唯一区别是,在我在按钮单击事件上调用此代码之前,但现在我在另一个线程上调用此代码,从Timer
.
如果是因为线程问题,有没有办法强制此代码在 UI 线程上运行?(或任何适当的线程)
注意:我正在 Xamarin.Android 中编写此应用程序,但本机 Android 中的答案对我有用。
解决方案
推荐阅读
- jquery - 下拉按钮不起作用也没有消失
- python-3.x - 如何用自定义类替换 h5py.AttributeManager?
- swift - 无法访问公共枚举 Swift 4.2
- visual-studio-code - Visual Studio Code 插入不可打印的控制字符
- excel - 查找值是表中行和列的连接
- jquery - 角度 6:无服务器联系表 aws
- wordpress - WP 和 get_pages 函数中的自定义字段
- java - Spring Boot 应用程序没有创建胖(超级)jar
- ssis - SSIS 并排运行多个步骤
- html - 在 flexbox 中设置基于百分比的高度