Skip to content

Commit b0fed82

Browse files
Allow Developers to Manually Request Permissions when using CameraView, FileSaver, FolderPicker and SpeechToText (#607)
* Allow Developers to Manually Request Permissions when using CameraView, FileSaver, FolderPicker and SpeechToText * update docs to split required and optional permissions * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 02e8726 commit b0fed82

4 files changed

Lines changed: 90 additions & 9 deletions

File tree

docs/maui/essentials/file-saver.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,35 @@ Add permissions to `tizen-manifest.xml`:
7272

7373
---
7474

75-
## Syntax
75+
## Basic usage
7676

77-
### C#
77+
The `FileSaver` can be added to a .NET MAUI application in the following way.
7878

79-
The `FileSaver` can be used as follows in C#:
79+
### Request permissions
80+
81+
Developers must manually request Permissions.StorageRead and Permissions.StorageWrite before saving files:
82+
83+
```csharp
84+
async Task RequestStoragePermissionsAndSaveFile(CancellationToken cancellationToken)
85+
{
86+
var readPermissionStatus = await Permissions.RequestAsync<Permissions.StorageRead>();
87+
var writePermissionStatus = await Permissions.RequestAsync<Permissions.StorageWrite>();
88+
89+
if (readPermissionStatus != PermissionStatus.Granted ||
90+
writePermissionStatus != PermissionStatus.Granted)
91+
{
92+
await Toast
93+
.Make("Storage permissions are required to save files.")
94+
.Show(cancellationToken);
95+
96+
return;
97+
}
98+
99+
await SaveFile(cancellationToken);
100+
}
101+
```
102+
103+
### Save file
80104

81105
```csharp
82106
async Task SaveFile(CancellationToken cancellationToken)

docs/maui/essentials/folder-picker.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,19 @@ Add permissions to `tizen-manifest.xml`:
6565

6666
---
6767

68-
## Syntax
68+
## Basic usage
6969

70-
### C#
70+
The `FolderPicker` can be added to a .NET MAUI application in the following way.
7171

72-
The `FolderPicker` can be used as follows in C#:
72+
### Request permissions
73+
74+
Developers must manually request Permissions.StorageRead:
75+
76+
```csharp
77+
var readPermissionsRequest = await Permissions.RequestAsync<Permissions.StorageRead>();
78+
```
79+
80+
### Pick folder
7381

7482
```csharp
7583
async Task PickFolder(CancellationToken cancellationToken)

docs/maui/essentials/speech-to-text.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,26 @@ Add permissions to `tizen-manifest.xml`:
5555

5656
---
5757

58-
## Syntax
58+
## Basic usage
5959

60-
### C#
60+
The `SpeechToText` can be added to a .NET MAUI application in the following way.
6161

62-
The `SpeechToText` can be used as follows in C#:
62+
### Request permissions
63+
64+
Developers must manually request Permissions.Microphone and also call ISpeechToText.RequestPermissions():
65+
66+
```csharp
67+
static async Task<bool> ArePermissionsGranted(ISpeechToText speechToText)
68+
{
69+
var microphonePermissionStatus = await Permissions.RequestAsync<Permissions.Microphone>();
70+
var isSpeechToTextRequestPermissionsGranted = await speechToText.RequestPermissions(CancellationToken.None);
71+
72+
return microphonePermissionStatus is PermissionStatus.Granted
73+
&& isSpeechToTextRequestPermissionsGranted;
74+
}
75+
```
76+
77+
### Speech To Text
6378

6479
```csharp
6580
async Task StartListening(CancellationToken cancellationToken)

docs/maui/views/camera-view.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ The following permissions need to be added to the `Platforms/Android/AndroidMani
2525
<uses-permission android:name="android.permission.CAMERA" />
2626
```
2727

28+
In case you plan to record video, request Microphone permissions:
29+
```xml
30+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
31+
```
32+
2833
This should be added inside the `<manifest>` element. Below shows a more complete example:
2934

3035
```xml
@@ -34,6 +39,9 @@ This should be added inside the `<manifest>` element. Below shows a more complet
3439

3540
<uses-permission android:name="android.permission.CAMERA" />
3641

42+
<!--Optional. Only for video recording-->
43+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
44+
3745
</manifest>
3846
```
3947

@@ -46,6 +54,12 @@ The following entries need to be added to the `Platforms/iOS/Info.plist` file:
4654
<string>PROVIDE YOUR REASON HERE</string>
4755
```
4856

57+
In case you plan to record video, request Microphone permissions:
58+
```xml
59+
<key>NSMicrophoneUsageDescription</key>
60+
<string>PROVIDE YOUR REASON HERE</string>
61+
```
62+
4963
This should be added inside the `<dict>` element. Below shows a more complete example:
5064

5165
```xml
@@ -96,6 +110,12 @@ The following entries need to be added to the `Platforms/MacCatalyst/Info.plist`
96110
<string>PROVIDE YOUR REASON HERE</string>
97111
```
98112

113+
In case you plan to record video, request Microphone permissions:
114+
```xml
115+
<key>NSMicrophoneUsageDescription</key>
116+
<string>PROVIDE YOUR REASON HERE</string>
117+
```
118+
99119
This should be added inside the `<dict>` element. Below shows a more complete example:
100120

101121
```xml
@@ -155,6 +175,20 @@ Tizen is not currently supported.
155175

156176
The `CameraView` can be added to a .NET MAUI application in the following way.
157177

178+
### Request permissions
179+
180+
Developers must manually request Permissions.Camera and/or Permissions.Microphone:
181+
182+
```csharp
183+
var cameraPermissionsRequest = await Permissions.RequestAsync<Permissions.Camera>();
184+
```
185+
186+
In case you plan to record video, request Microphone permissions:
187+
188+
```csharp
189+
var microphonePermissionsRequest = await Permissions.RequestAsync<Permissions.Microphone>();
190+
```
191+
158192
### Including the XAML namespace
159193

160194
[!INCLUDE [XAML usage guidance](../includes/xaml-usage.md)]

0 commit comments

Comments
 (0)