48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using Android.App;
|
|
using Android.Content.PM;
|
|
using Android.OS;
|
|
using Android;
|
|
using AndroidX.Core.App;
|
|
using AndroidX.Core.Content;
|
|
|
|
namespace NotVPR_Remote
|
|
{
|
|
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop,
|
|
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode |
|
|
ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
|
|
public class MainActivity : MauiAppCompatActivity
|
|
{
|
|
const int RequestBluetoothPermissionsId = 1000;
|
|
|
|
protected override void OnCreate(Bundle savedInstanceState)
|
|
{
|
|
base.OnCreate(savedInstanceState);
|
|
|
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.S)
|
|
{
|
|
string[] permissions =
|
|
{
|
|
Manifest.Permission.BluetoothScan,
|
|
Manifest.Permission.BluetoothConnect,
|
|
Manifest.Permission.AccessFineLocation // Needed for scanning on some devices
|
|
};
|
|
|
|
if (!HasPermissions(permissions))
|
|
{
|
|
ActivityCompat.RequestPermissions(this, permissions, RequestBluetoothPermissionsId);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool HasPermissions(string[] permissions)
|
|
{
|
|
foreach (var permission in permissions)
|
|
{
|
|
if (ContextCompat.CheckSelfPermission(this, permission) != Permission.Granted)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|