diff --git a/App/RobobinApp/Platforms/Android/AndroidManifest.xml b/App/RobobinApp/Platforms/Android/AndroidManifest.xml index bdec9b5900dda15071a0a17a6027978e22c74f0b..5601ae70438db4f60b0117531e4f2bd8f1dec22c 100644 --- a/App/RobobinApp/Platforms/Android/AndroidManifest.xml +++ b/App/RobobinApp/Platforms/Android/AndroidManifest.xml @@ -1,6 +1,13 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android"> - <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> - <uses-permission android:name="android.permission.INTERNET" /> +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1"> + <application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="RoboBin"></application> + <!-- Required permissions --> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.BLUETOOTH" /> + <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> + <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> + <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> + <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" /> + <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> </manifest> \ No newline at end of file diff --git a/App/RobobinApp/RobobinApp.csproj b/App/RobobinApp/RobobinApp.csproj index 4a445af54da62b7ae14b333adfdfa9216f1c317a..03a33ca2f46e573a305b8344631c524e78686e1a 100644 --- a/App/RobobinApp/RobobinApp.csproj +++ b/App/RobobinApp/RobobinApp.csproj @@ -61,6 +61,7 @@ <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" /> + <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.91" /> <PackageReference Include="Plugin.BLE" Version="3.1.0" /> <PackageReference Include="Shiny" Version="2.7.3" /> <PackageReference Include="Shiny.BluetoothLE" Version="3.3.3" /> diff --git a/App/RobobinApp/RobobinApp.csproj.user b/App/RobobinApp/RobobinApp.csproj.user index d5dbc44f4a17c86bc16c6e731262903590f5f0a1..8081d85ab90d22b8d910eae519a130ae46099072 100644 --- a/App/RobobinApp/RobobinApp.csproj.user +++ b/App/RobobinApp/RobobinApp.csproj.user @@ -2,8 +2,8 @@ <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen> - <ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework> - <ActiveDebugProfile>Windows Machine</ActiveDebugProfile> + <ActiveDebugFramework>net8.0-android</ActiveDebugFramework> + <ActiveDebugProfile>Pixel 5 - API 34 (Android 14.0 - API 34)</ActiveDebugProfile> <SelectedPlatformGroup>Emulator</SelectedPlatformGroup> <DefaultDevice>pixel_5_-_api_34</DefaultDevice> </PropertyGroup> diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index fe675991f21ac7576e19d9d32c029db7e1de94ba..f79e46b4a046979fcccee9101eef959bb4997ee8 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -5,6 +5,7 @@ using RobobinApp.Views; using Plugin.BLE; using Plugin.BLE.Abstractions.Contracts; using Plugin.BLE.Abstractions.Exceptions; +//using Microsoft.Maui.E namespace RobobinApp.ViewModels { @@ -29,7 +30,8 @@ namespace RobobinApp.ViewModels _bluetoothLE = CrossBluetoothLE.Current; _adapter = _bluetoothLE.Adapter; - ScanDevices(); // Start scanning for devices + // Check and request Bluetooth permissions before scanning + CheckAndRequestBluetoothPermissions(); } public BluetoothDevice SelectedDevice @@ -42,6 +44,29 @@ namespace RobobinApp.ViewModels } } + + private async void CheckAndRequestBluetoothPermissions() + { + // Check if the Bluetooth scan permission is granted + var status = await Permissions.CheckStatusAsync<Permissions.Bluetooth>(); + if (status != PermissionStatus.Granted) + { + // Request permission + status = await Permissions.RequestAsync<Permissions.Bluetooth>(); + } + + if (status == PermissionStatus.Granted) + { + // Permission granted, proceed with scanning devices + ScanDevices(); + } + else + { + // Permission denied, handle accordingly + await Application.Current.MainPage.DisplayAlert("Permissions", "Bluetooth scan permission is required to discover devices.", "OK"); + } + } + public async Task OnGoHome() { await Application.Current.MainPage.Navigation.PushAsync(new MainPage()); diff --git a/App/RobobinApp/ViewModels/MainPageViewModel.cs b/App/RobobinApp/ViewModels/MainPageViewModel.cs index 8665557a0fd8f7db1b5f3df628bd0300c238fe2d..784b95043026d824087567f31286057b2edd890c 100644 --- a/App/RobobinApp/ViewModels/MainPageViewModel.cs +++ b/App/RobobinApp/ViewModels/MainPageViewModel.cs @@ -8,6 +8,7 @@ using Shiny.BluetoothLE; namespace RobobinApp.ViewModels { + //https://docs.ros.org/en/jazzy/Concepts/Intermediate/About-Domain-ID.html <- Should just work once wifi connection public class MainPageViewModel : INotifyPropertyChanged { private bool _isBusy; diff --git a/App/RobobinApp/Views/ConnectionPage.xaml.cs b/App/RobobinApp/Views/ConnectionPage.xaml.cs index 446d016579e3e40a5c7a3a520c15d146add14b27..27c0fce5902a1796e1ef0d37fee26d545d4fbfc0 100644 --- a/App/RobobinApp/Views/ConnectionPage.xaml.cs +++ b/App/RobobinApp/Views/ConnectionPage.xaml.cs @@ -6,4 +6,5 @@ public partial class ConnectionPage : ContentPage { InitializeComponent(); } + } \ No newline at end of file diff --git a/App/RobobinApp/Views/MainPage.xaml b/App/RobobinApp/Views/MainPage.xaml index 983bcd12495213e5119ecb9bcb3aa90451ca1b34..75869e06f59bce52d8b37309c1ad5fb66a191a91 100644 --- a/App/RobobinApp/Views/MainPage.xaml +++ b/App/RobobinApp/Views/MainPage.xaml @@ -42,7 +42,7 @@ <Frame BackgroundColor="Lavender" BorderColor="Black" CornerRadius="5" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="2" Grid.Row="0"> - <Label Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center"/> + <Button Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center" Command="{Binding ConnectToRobobinCommand}"/> </Frame> </Grid> </ContentPage>