0

I'm trying to use Bluetooth in .Net Maui app using the following code :

static BluetoothAdapter bluetoothAdapter;

bluetoothAdapter = BluetoothAdapter.DefaultAdapter;

But I'm getting warning saying:

'BluetoothAdapter.DefaultAdapter' is obsoleted on: 'Android' 31.0 and later

How can I solve that?

halfer
  • 19,824
  • 17
  • 99
  • 186
Thomas Carlton
  • 5,344
  • 10
  • 63
  • 126
  • 2
    Does this answer your question? [What do I use now that BluetoothAdapter.getDefaultAdapter() is deprecated?](https://stackoverflow.com/questions/69122978/what-do-i-use-now-that-bluetoothadapter-getdefaultadapter-is-deprecated) – Jason Jul 25 '23 at 20:35
  • Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Jul 26 '23 at 11:20

1 Answers1

0

In Maui, you can get the BluetoothAdapter like this:

public BluetoothAdapter GetBluetoothAdapter()
{
   var bluetoothManager = MauiApplication.Current.GetSystemService("bluetooth") as BluetoothManager;
   return bluetoothManager.Adapter;
}
tval
  • 412
  • 3
  • 17