Office.DevicePermissionType enum

アドインがアクセスを要求しているデバイス機能を指定します。

注釈

アプリケーション: この API は、Microsoft Edge や Google Chrome などの Chromium ベースのブラウザーで実行する場合、次の Office アプリケーションでサポートされます。

  • Excel on the web

  • Outlook on the web

  • PowerPoint on the web

  • Word on the web

新しい 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 on the webおよび新しい Outlook on Windows (プレビュー) でのみサポートされます。

microphone

アドインは、ユーザーのマイクへのアクセスを要求しています。