|
|
@@ -0,0 +1,33 @@
|
|
|
+using InABox.Core;
|
|
|
+using Microsoft.Maui.ApplicationModel;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace InABox.Avalonia.Platform.Android;
|
|
|
+
|
|
|
+public class Android_Permissions : IPermissions
|
|
|
+{
|
|
|
+ public Logger? Logger { get; set; }
|
|
|
+
|
|
|
+ public async Task<bool> IsPermitted(Permission permission)
|
|
|
+ {
|
|
|
+ if (permission == Permission.Camera)
|
|
|
+ return await DoEnabled<Permissions.Camera>();
|
|
|
+ if (permission == Permission.PhotoLibrary || permission == Permission.VideoLibrary)
|
|
|
+ return await DoEnabled<Permissions.Photos>();
|
|
|
+ if (permission == Permission.Geolocation)
|
|
|
+ return await DoEnabled<Permissions.LocationWhenInUse>();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> DoEnabled<TPermission>() where TPermission : Permissions.BasePlatformPermission, new()
|
|
|
+ {
|
|
|
+ var status = await Permissions.CheckStatusAsync<TPermission>();
|
|
|
+ if (status != PermissionStatus.Granted && status != PermissionStatus.Restricted)
|
|
|
+ status = await Permissions.RequestAsync<TPermission>();
|
|
|
+ return status == PermissionStatus.Granted;
|
|
|
+ }
|
|
|
+}
|