Bluetooth機能を備えたAndroidアプリケーションを開発しています。しかし、私には1つの問題があります。私は次のコードを使用しています
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
tv.setText("Device is not there");
setContentView(tv);
}
else
{
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
tv.setText("Device is there");
setContentView(tv);
}
でエラーが発生します
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
そのコードを実行しようとすると、[強制終了]ボタンのあるメッセージボックスが表示されてアプリケーションがクラッシュします。エラーはどこにありますか、私はまだそれを理解していません。親切に助けてください。よろしく