PermissionTexts: Custom the Permission Texts for Dialogs and Drawers

更新时间:
2024-06-19
下载文档

PermissionTexts: Custom the Permission Texts for Dialogs and Drawers

The permissionTexts module provides many interfaces for applications to manage the permission texts for dialogs and drawers.

Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error);
});

You need to use canIUse API to determine whether the API can be used.

const canIUse = edger.canIUse({
  name: 'permissionTexts.register'
})

if (canIUse) {
  // Here you can use `edger.permissionTexts.register`
}

Functions

edger.permissionTexts.register(params)

Register permission texts for the current EAP.

  • params {Array<PermissionText>} The array of the PermissionText.
  • Returns: {Promise<{success: boolean}>} Promise object.

The params is an array of the PermissionText. Each PermissionText item contains the following members:

  • type {String} Consistent with the type in edger.permission.request(option) API. Permission types: permissions | devices | phone | vehicle. Currently, the vehicle type is not supported.
  • code {String} Consistent with the type in edger.permission.request(option) API.
  • dialogContent {string} Permission dialog content. This parameter can modify the permission content of dialog, such as the permission dialog triggered by edger.fs.showMediaSelector(options). Optional.
  • drawerContent {string} Permission drawer content. This parameter can modify the permission content of edger.permission.request(option) API. The edger.permissionTexts.register(options) API must be called before edger.permission.request(option) API. Optional.

The corresponding table of permission request types and code is as follows:

typecode
permissionsainn, alarm, share, notify, advnwc, network, display, rtsp, lora, coap, wallpaper, account, printer, auxstorage, vpn, mqtt.publish, mqtt.subscribe, mediacenter.readable, mediacenter.writable, mediacenter.removable
devicesList of allowed device IDs
phonecamera, microphone, geolocation , browser, media, file, contacts
vehiclemedia, geolocation, diagnostic, cockpit, drive

Example

edger.permissionTexts.register([{
  type: 'phone',
  code: 'media', 
  dialogContent: '请前往手机设置为爱智 App 开启“相册”权限',
  drawerContent: '请前往手机设置为爱智 App 开启“相册”权限'
}]).then((data) => {
  console.log(data.success)
})

async / await

try {
  const { success } = await edger.permissionTexts.register([{
    type: 'phone',
    code: 'media', 
    dialogContent: '请前往手机设置为爱智 App 开启“相册”权限',
    drawerContent: '请前往手机设置为爱智 App 开启“相册”权限'
  }])
  console.log(success)
} catch (error) {
  console.error(error);
}

edger.permissionTexts.unregister(params)

Unregister permission texts for the current EAP.

  • params {Array<UnregisterParam>} The array of the UnregisterParam.
  • Returns: {Promise<{success: boolean}>} Promise object.

The params is array of the UnregisterParam. If this params is empty, it means unregister all permission texts. Optional.

Each Param item contains the following members:

  • type {String} Permission type.
  • code {String} Permission code.

Example

edger.permissionTexts.unregister([{
  type: 'phone',
  code: 'media'
}]).then(data => {
  console.log(data.success)
})

async / await

try {
  const { success } = await edger.permissionTexts.unregister([{
    type: 'phone',
    code: 'media'
  }]);
  console.log(success)
} catch (error) {
  console.error(error);
}

edger.permissionTexts.query()

Query registrarion texts for the current EAP.

  • Returns: {Promise< { result: Array<PermissionText> } >}.

Example

edger.permissionTexts.query().then(data => {
  console.log(data.result)
})

async / await

try {
  const { result } = await edger.permissionTexts.query();
  // eg: 
  // result = [{
  //     type: 'phone',
  //     code: 'media', 
  //     dialogContent: '请前往手机设置为爱智 App 开启“相册”权限',
  //     drawerContent: '请前往手机设置为爱智 App 开启“相册”权限'
  // }]
  console.log(result)
} catch (error) {
  console.error(error);
}
文档内容是否对您有所帮助?
有帮助
没帮助