-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainPage.xaml.cs
60 lines (49 loc) · 2 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#if ANDROID
using Android.Content;
#endif
namespace MauiApp6;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnCounterClicked(object sender, EventArgs e)
{
Task.Run(async () =>
{
await MainThread.InvokeOnMainThreadAsync(async () =>
{
try
{
await RequestPermissionAsync();
#if ANDROID
Intent intent = new Intent(Platform.CurrentActivity.Application.ApplicationContext, typeof(Platforms.Android.OcrActivity));
intent.SetFlags(ActivityFlags.NewTask);
Platform.CurrentActivity.Application.ApplicationContext.StartActivity(intent);
#endif
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
});
});
}
private async Task RequestPermissionAsync()
{
var cameraStatus = await Permissions.CheckStatusAsync<Permissions.Camera>(); //.CheckPermissionStatusAsync(Permission.Camera);
//var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
if (cameraStatus != PermissionStatus.Granted /*|| storageStatus != PermissionStatus.Granted*/)
{
cameraStatus = await Permissions.RequestAsync<Permissions.Camera>();
//var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera/*, Permission.Storage*/ });
//cameraStatus = results[Permission.Camera];
//storageStatus = results[Permission.Storage];
}
if (cameraStatus != PermissionStatus.Granted /*&& storageStatus == PermissionStatus.Granted*/)
{
await Application.Current.MainPage.DisplayAlert("Error", "Grant camera permission", "Ok");
}
}
}