Hello,
How to call this in my required ViewModel
You implement the interface on Windows platform, but you don't know how to call the method in single shared MAUI project, right? If so, you could add a method in your ViewModel
class and use conditional compilation to target Windows platforms. Or you can invoke the platform code directly. Please refer to the following code:
#if WINDOWS
Using ZolaApplication.Platforms.Windows
#endif
public class ViewModel{
public async void iSEnableAsync()
{
#if WINDOWS
// invoke the method you defined
//Bluetooth bluetooth = new Bluetooth();
// bool isEnable = await bluetooth.GetBluetoothIsEnabledAsync();
//invoke the platform code directly
var accessLevel = await Radio.RequestAccessAsync();// request access
if (accessLevel != RadioAccessStatus.Allowed)
{
Debug.WriteLine("Failed");
}
else
{
var radios = await Radio.GetRadiosAsync();
var bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth);
bool isEnable = bluetoothRadio != null && bluetoothRadio.State == RadioState.On;
if (isEnable){...}
}
#endif
}
}
And you could call the method.
private void OnCounterClicked(object sender, EventArgs e)
{
var VM = this.BindingContext as ViewModel;
VM.iSEnableAsync();
}
In addition, please pay attention to pay attention to adding capability in Package.appxmanifest : <DeviceCapability Name="radios"/>
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.