-
Notifications
You must be signed in to change notification settings - Fork 62
/
office.devicepermissiontype.yml
121 lines (92 loc) · 4.24 KB
/
office.devicepermissiontype.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
### YamlMime:TSEnum
name: Office.DevicePermissionType
uid: 'office!Office.DevicePermissionType:enum'
package: office!
fullName: Office.DevicePermissionType
summary: Specifies the device capability to which an add-in is requesting access.
remarks: >-
**Applications**: This API is supported by the following Office applications when running in Chromium-based
browsers, such as Microsoft Edge and Google Chrome.
- Excel on the web
- Outlook on the web
- PowerPoint on the web
- Word on the web
It's also supported in [new Outlook on Windows
(preview)](https://support.microsoft.com/office/656bb8d9-5a60-49b2-a98b-ba7822bc7627)<!-- -->.
**Requirement set**: [DevicePermission
1.1](https://learn.microsoft.com/javascript/api/requirement-sets/common/device-permission-service-requirement-sets)
#### Examples
```TypeScript
// Request permission from a user to access their device capabilities.
const host = Office.context.host;
if (host === Office.HostType.Excel || host === Office.HostType.PowerPoint || host === Office.HostType.Word) {
if (Office.context.platform === Office.PlatformType.OfficeOnline) {
const deviceCapabilities = [
Office.DevicePermissionType.camera,
Office.DevicePermissionType.microphone
];
Office.devicePermission
.requestPermissions(deviceCapabilities)
.then((isGranted) => {
if (isGranted) {
console.log("Permission granted.");
// Reload your add-in before you run code that uses the device capabilities.
location.reload();
} else {
console.log("Permission has been previously granted and is already set in the iframe.");
// Since permission has been previously granted, you don't need to reload your add-in.
// Do something with the device capabilities.
}
})
.catch((error) => {
console.log("Permission denied.");
console.error(error);
// Do something when permission is denied.
});
}
} else if (host === Office.HostType.Outlook) {
if (Office.context.mailbox.diagnostics.hostName === "OutlookWebApp") {
const deviceCapabilities = [
Office.DevicePermissionType.camera,
Office.DevicePermissionType.geolocation,
Office.DevicePermissionType.microphone
];
Office.devicePermission.requestPermissionsAsync(deviceCapabilities, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log("Permission denied.");
// Do something when permission is denied.
} else {
if (asyncResult.value) {
console.log("Permission granted.");
// Reload your add-in before you run code that uses the device capabilities.
location.reload();
} else {
console.log("Permission has been previously granted and is already set in the iframe.");
// Since permission has been previously granted, you don't need to reload your add-in.
// Do something with the device capabilities.
}
}
});
}
} else {
console.log("The add-in isn't running in Excel, Outlook, PowerPoint, or Word.");
}
```
isPreview: false
isDeprecated: false
fields:
- name: camera
uid: 'office!Office.DevicePermissionType.camera:member'
package: office!
summary: The add-in is requesting access to the user's camera.
- name: geolocation
uid: 'office!Office.DevicePermissionType.geolocation:member'
package: office!
summary: >-
The add-in is requesting access to the user's geolocation.
**Important**: Access to a user's geolocation is only supported in Outlook on the web and new Outlook on
Windows (preview).
- name: microphone
uid: 'office!Office.DevicePermissionType.microphone:member'
package: office!
summary: The add-in is requesting access to the user's microphone.