Skip to content

Commit

Permalink
Basic idea for a fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ShortDevelopment committed Jul 18, 2024
1 parent ae4cb7d commit ec85d9a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using AndroidX.Core.App;
using Google.Android.Material.Card;

namespace NearShare.Droid;
Expand All @@ -24,7 +25,7 @@ protected override void OnCreate(Bundle? savedInstanceState)
Button receiveButton = FindViewById<Button>(Resource.Id.receiveButton)!;
receiveButton.Click += ReceiveButton_Click;

FindViewById<MaterialCardView>(Resource.Id.enableBluetoothButton)!.Click += (_, _) => StartActivity(new Intent(BluetoothAdapter.ActionRequestEnable));
FindViewById<MaterialCardView>(Resource.Id.enableBluetoothButton)!.Click += (_, _) => EnableBluetooth();
FindViewById<MaterialCardView>(Resource.Id.setupWindowButton)!.Click += (_, _) => UIHelper.OpenSetup(this);
FindViewById<MaterialCardView>(Resource.Id.openFAQButton)!.Click += (_, _) => UIHelper.OpenFAQ(this);
}
Expand Down Expand Up @@ -89,4 +90,21 @@ public override bool OnCreateOptionsMenu(IMenu? menu)

public override bool OnOptionsItemSelected(IMenuItem item)
=> UIHelper.OnOptionsItemSelected(this, item);

private void EnableBluetooth()
{
if (OperatingSystem.IsAndroidVersionAtLeast(31))
ActivityCompat.RequestPermissions(this, [ManifestPermission.BluetoothConnect], EnableBluetoothCode);
else
StartActivity(new Intent(BluetoothAdapter.ActionRequestEnable));
}

const int EnableBluetoothCode = 0x2;
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
if (requestCode != EnableBluetoothCode || grantResults.Any(x => x != Android.Content.PM.Permission.Granted))
return;

StartActivity(new Intent(BluetoothAdapter.ActionRequestEnable));
}
}

0 comments on commit ec85d9a

Please sign in to comment.