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.");

                    // Do something when permission is granted.
                } else {
                    console.log("Permission denied.");

                    // 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 (asyncResult.error.message);
                return;
            }

            if (asyncResult.value) {
                console.log("Permission granted.");

                // Do something when permission is granted.
            } else {
                console.log("Permission denied.");

                // Do something when permission is denied.
            }
        });
    }
} else {
    console.log("The add-in isn't running in Excel, Outlook, PowerPoint, or Word.");
}

字段

camera

加载项正在请求访问用户的相机。

geolocation

加载项正在请求访问用户的地理位置。

重要提示:仅Outlook 网页版和新的 Windows 版 Outlook (预览版) 中支持访问用户的地理位置。

microphone

加载项正在请求访问用户的麦克风。