Office.DevicePermissionType enum
Especifica a capacidade do dispositivo à qual um suplemento está a pedir acesso.
Comentários
Aplicações: esta API é suportada pelas seguintes aplicações do Office ao executar em browsers baseados em Chromium, como o Microsoft Edge e o Google Chrome.
Excel Online
Outlook na Web
PowerPoint Online
Word Online
Também é suportado no novo Outlook no Windows.
Conjunto de requisitos: DevicePermission 1.1
Exemplos
// 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.");
}
Campos
camera | O suplemento está a pedir acesso à câmara do utilizador. |
geolocation | O suplemento está a pedir acesso à geolocalização do utilizador. Importante: o acesso à geolocalização de um utilizador só é suportado no Outlook na Web e no novo Outlook no Windows. |
microphone | O suplemento está a pedir acesso ao microfone do utilizador. |