0
我正在嘗試我的第一個Android項目,但無法使BluetoothAdapter工作。我在Visual Studio中使用運行Android 4.4(API 19)的nexus 5仿真器中的Xamarin。獲取藍牙適配器與Xamarin Android API 19或更高版本
我嘗試以下代碼
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
bluetoothAdapter.Enable();
而得到一個錯誤信息
System.NullReferenceException:對象引用不設置到的一個實例>對象
我還試用
BluetoothAdapter bluetoothAdapter = (BluetoothAdapter)this.GetSystemService(Context.BluetoothService);
bluetoothAdapter.Enable();
,並再次得到了一個錯誤
System.InvalidCastException:指定的轉換無效。
這可能是一個非常基本的問題,但似乎一些支持已經過時,因爲從Android 4.3開始,藍牙適配器以新的方式創建。
謝謝!
亞歷