Office.DevicePermissionType enum
指定外接程序请求访问的设备功能。
注解
应用程序:在基于 Chromium 的浏览器(如 Microsoft Edge 和 Google Chrome)中运行时,以下 Office 应用程序支持此 API。
Excel 网页版
Outlook 网页版
PowerPoint 网页版
Word 网页版
新的 Outlook on Windows 也支持它。
要求集: DevicePermission 1.1
示例
// 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.");
}
字段
camera | 加载项正在请求访问用户的相机。 |
geolocation | 加载项正在请求访问用户的地理位置。 重要提示:仅Outlook 网页版和新的 Windows 版 Outlook 中支持访问用户的地理位置。 |
microphone | 加载项正在请求访问用户的麦克风。 |