让蓝牙适配器与 Android API 19 或更高版本的 Xamarin 一起使用
Getting Bluetooth Adapter working with Xamarin for Android API 19 or above
我正在尝试我的第一个 android 项目,但无法让 BluetoothAdapter 工作。我在 Visual Studio 中使用 Xamarin 和 nexus 5 模拟器 运行 Android 4.4 (API 19).
我试过下面的代码
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
bluetoothAdapter.Enable();
并收到一条错误消息
System.NullReferenceException: Object reference not set to an instance of an > object
我也试过了
BluetoothAdapter bluetoothAdapter = (BluetoothAdapter)this.GetSystemService(Context.BluetoothService);
bluetoothAdapter.Enable();
再次出错
System.InvalidCastException: Specified cast is not valid.
这可能是一个非常基本的问题,但似乎某些支持已经过时,因为从 Android 4.3 开始,蓝牙适配器是以一种新的方式创建的。
谢谢!
亚历克斯
Android 模拟器不支持蓝牙,无论是 Android SDK 还是 Visual Studio Android 模拟器。文档中是这么规定的。
看这里:https://developer.android.com/studio/run/emulator.html#about
我正在尝试我的第一个 android 项目,但无法让 BluetoothAdapter 工作。我在 Visual Studio 中使用 Xamarin 和 nexus 5 模拟器 运行 Android 4.4 (API 19).
我试过下面的代码
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
bluetoothAdapter.Enable();
并收到一条错误消息
System.NullReferenceException: Object reference not set to an instance of an > object
我也试过了
BluetoothAdapter bluetoothAdapter = (BluetoothAdapter)this.GetSystemService(Context.BluetoothService);
bluetoothAdapter.Enable();
再次出错
System.InvalidCastException: Specified cast is not valid.
这可能是一个非常基本的问题,但似乎某些支持已经过时,因为从 Android 4.3 开始,蓝牙适配器是以一种新的方式创建的。
谢谢!
亚历克斯
Android 模拟器不支持蓝牙,无论是 Android SDK 还是 Visual Studio Android 模拟器。文档中是这么规定的。
看这里:https://developer.android.com/studio/run/emulator.html#about