私の最初のAndroidプロジェクトを試していますが、Bluetoothアダプターの動作に問題があります。私はAndroid 4.4(API 19)を実行しているnexus 5エミュレータでVisual StudioでXamarinを使用しています。BluetoothアダプターをXamarin for Android API 19以上で使用する
Iは、次のコード
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;
bluetoothAdapter.Enable();
を試み、エラーメッセージ
System.NullReferenceException得た:オブジェクト参照>オブジェクト
Iものインスタンスに設定されていません試しました
BluetoothAdapter bluetoothAdapter = (BluetoothAdapter)this.GetSystemService(Context.BluetoothService);
bluetoothAdapter.Enable();
と再びエラー
System.InvalidCastExceptionのだ:指定されたキャストは有効ではありません。
これは非常に基本的な質問かもしれませんが、Android 4.3以降では新しい方法でBluetoothアダプタが作成されているため、サポートの一部が古くなっているようです。
ありがとうございます!
アレックス