harmony(鸿蒙)Enterprise Device Management

2022-08-09 浏览 (905)

Enterprise Device Management

The enterpriseDeviceManager module provides enterprise device management capabilities so that devices have the customization capabilities required in enterprise scenarios.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager';

enterpriseDeviceManager.enableAdmin

enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback<boolean>): void

Enables a device administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
typeAdminTypeYesType of the device administrator to enable.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
    name: "enterprise name",
    description: "enterprise description"
}
enterpriseDeviceManager.enableAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.enableAdmin

enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback<boolean>): void

Enables a device administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
typeAdminTypeYesType of the device administrator to enable.
userIdnumberYesUser ID The default value is the user ID of the caller. The value must be greater than or equal to 0.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
    name: "enterprise name",
    description: "enterprise description"
}
enterpriseDeviceManager.enableAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, 100, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.enableAdmin

enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise<boolean>

Enables a device administrator application based on the specified bundle name and class name. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
typeAdminTypeYesType of the device administrator to enable.
userIdnumberNoUser ID The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
    name: "enterprise name",
    description: "enterprise description"
}
enterpriseDeviceManager.enableAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, 100)
.then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.disableAdmin

disableAdmin(admin: Want, callback: AsyncCallback<boolean>): void

Disables a device common administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice common administrator application.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.disableAdmin(wantTemp, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.disableAdmin

disableAdmin(admin: Want, userId: number, callback: AsyncCallback<boolean>): void

Disables a device common administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice common administrator application.
userIdnumberYesUser ID The default value is the user ID of the caller. The value must be greater than or equal to 0.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.disableAdmin(wantTemp, 100, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.disableAdmin

disableAdmin(admin: Want, userId?: number): Promise<boolean>

Disables a device common administrator application based on the specified bundle name and class name. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice common administrator application.
userIdnumberNoUser ID The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.disableAdmin(wantTemp, 100).then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.disableSuperAdmin

disableSuperAdmin(bundleName: String, callback: AsyncCallback<boolean>): void

Disables a device super administrator application based on the specified bundle name. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
bundleNameStringYesBundle name of the device super administrator application.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let bundleName = "com.example.myapplication";
enterpriseDeviceManager.disableSuperAdmin(bundleName, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.disableSuperAdmin

disableSuperAdmin(bundleName: String): Promise<boolean>

Disables a device super administrator application based on the specified bundle name. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
bundleNameStringYesBundle name of the device super administrator application.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

let bundleName = "com.example.myapplication";
enterpriseDeviceManager.disableSuperAdmin(bundleName).then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.isAdminEnabled

isAdminEnabled(admin: Want, callback: AsyncCallback<boolean>): void

Checks whether a device administrator application is enabled based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminEnabled(wantTemp, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.isAdminEnabled

isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback<boolean>): void

Checks whether a device administrator application is enabled based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
userIdnumberYesUser ID The default value is the user ID of the caller. The value must be greater than or equal to 0.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminEnabled(wantTemp, 100, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.isAdminEnabled

isAdminEnabled(admin: Want, userId?: number): Promise<boolean>

Checks whether a device administrator application is enabled based on the specified bundle name and class name. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
userIdnumberNoUser ID The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminEnabled(wantTemp, 100).then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.isSuperAdmin

isSuperAdmin(bundleName: String, callback: AsyncCallback<boolean>): void

Checks whether a device super administrator application is enabled based on the specified bundle name. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
bundleNameStringYesDevice administrator application.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log("result is " + result);
});

enterpriseDeviceManager.isSuperAdmin

isSuperAdmin(bundleName: String): Promise<boolean>

Checks whether a device super administrator application is enabled based on the specified bundle name. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
bundleNameStringYesDevice super administrator application.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName).then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.getDeviceSettingsManager

getDeviceSettingsManager(callback: AsyncCallback<DeviceSettingsManager>): void

Obtains a DeviceSettingsManager object. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<DeviceSettingsManager>YesCallback used to return the DeviceSettingsManager object obtained.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    mgr.setDateTime(wantTemp, 1526003846000, (error, value) => { 
        if (error != null) {
            console.log(error);
        } else {
            console.log(value);
        }
    });
});

enterpriseDeviceManager.getDeviceSettingsManager

getDeviceSettingsManager(): Promise<DeviceSettingsManager>

Obtains a DeviceSettingsManager object. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Return value

TypeDescription
Promise<DeviceSettingsManager>Promise used to return the DeviceSettingsManager object obtained.

Example

let wantTemp = {
    bundleName: "bundleName",
    abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager().then((mgr) => {
    mgr.setDateTime(wantTemp, 1526003846000).then((value) => {
        console.log(value);
    }).catch((error) => {
        console.log(error);
    })
}).catch((error) => {
    console.log(error);
})

enterpriseDeviceManager.setEnterpriseInfo

setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback<boolean>): void

Sets the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.
callbackAsyncCallback<boolean>YesCallback used to return the result.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
    name: "enterprise name",
    description: "enterprise description"
}
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo)
.then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.setEnterpriseInfo

setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise<boolean>

Sets the enterprise information of a device administrator application. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
enterpriseInfoEnterpriseInfoYesEnterprise information of the device administrator application.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
    name: "enterprise name",
    description: "enterprise description"
}
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo)
.then((result) => {
    console.log("result is " + result);
}).catch(error => {
    console.log("error occurs" + error);
});

enterpriseDeviceManager.getEnterpriseInfo

getEnterpriseInfo(admin: Want, callback: AsyncCallback<EnterpriseInfo>): void

Obtains the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.
callbackAsyncCallback<EnterpriseInfo>YesCallback used to return the enterprise information of the device administrator application.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
enterpriseDeviceManager.getEnterpriseInfo(wantTemp, (error, result) => {
    if (error != null) {
        console.log("error occurs" + error);
        return;
    }
    console.log(result.name);
    console.log(result.description);
});

enterpriseDeviceManager.getEnterpriseInfo

getEnterpriseInfo(admin: Want): Promise<EnterpriseInfo>

Obtains the enterprise information of a device administrator application. This API uses a promise to return the result.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

Parameters

NameTypeMandatoryDescription
adminWantYesDevice administrator application.

Return value

TypeDescription
Promise<EnterpriseInfo>Promise used to return the enterprise information of the device administrator application.

Example

let wantTemp = {
    bundleName: "com.example.myapplication",
    abilityName: "com.example.myapplication.MainAbility",
};
enterpriseDeviceManager.getEnterpriseInfo(wantTemp).then((result) => {
    console.log(result.name);
    console.log(result.description);
}).catch(error => {
    console.log("error occurs" + error);
});

EnterpriseInfo

Describes the enterprise information of a device administrator application.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameReadable/WritableTypeMandatoryDescription
nameRead onlystringYesName of the enterprise to which the device administrator application belongs.
descriptionRead onlystringYesDescription of the enterprise to which the device administrator application belongs.

AdminType

Enumerates the administrator types of the device administrator application.

System capability: SystemCapability.Customization.EnterpriseDeviceManager

NameDefault ValueDescription
ADMIN_TYPE_NORMAL0x00Common administrator.
ADMIN_TYPE_SUPER0x01Super administrator.

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)APIs

harmony(鸿蒙)API Reference Document Description

harmony(鸿蒙)BundleStatusCallback

harmony(鸿蒙)innerBundleManager

harmony(鸿蒙)distributedBundle

harmony(鸿蒙)Bundle

harmony(鸿蒙)Context

harmony(鸿蒙)DataUriUtils

harmony(鸿蒙)EnterpriseAdminExtensionAbility

harmony(鸿蒙)Work Scheduler Callbacks

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/6eaa11a9bc7049b6b9ef8e3d384a65de