Office.DevicePermissionType enum
Especifica la funcionalidad del dispositivo a la que un complemento solicita acceso.
Comentarios
Aplicaciones: esta API es compatible con las siguientes aplicaciones de Office cuando se ejecutan en exploradores basados en Chromium, como Microsoft Edge y Google Chrome.
Excel en la web
Outlook en la Web
PowerPoint en la web
Word en la web
También se admite en el nuevo Outlook en Windows.
Conjunto de requisitos: DevicePermission 1.1
Ejemplos
// 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 | El complemento solicita acceso a la cámara del usuario. |
geolocation | El complemento solicita acceso a la geolocalización del usuario. Importante: El acceso a la geolocalización de un usuario solo se admite en Outlook en la Web y nueva Outlook en Windows. |
microphone | El complemento solicita acceso al micrófono del usuario. |