SystemShare: Thirdparty Mobile App Sharing

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

SystemShare: Thirdparty Mobile App Sharing

This share module provides many interfaces for sharing files such as pictures, audio, videos, and documents through native apps.

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

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

Functions

edger.share.open(params)

Open the sharing panel.

  • params {Object} Parameters for creating services.
  • Returns: {Promise}.

The params is the service parameter object, it can contain the following members:

  • channelType {String} The specified shared channel. Default: system. Optional.
  • contentType {String} The specified shared content type. Optional values: file | link.
  • content {Object} Shared content.

When the contentType is file, the content attribute in params is an object, it can contain the following members:

  • name {String} The file name that does not contain an extension.
  • type {String} Type of the file. For example: png, jpg, pdf, docx, etc.
  • url {String} URL of the file.
  • headers {Object} Media request headers. Optional.

When the contentType is link, the content attribute in params is an object, it can contain the following members:

  • url {String} Link address.
  • title {String} Content title.
  • imgUrl {String} Link cover image address.

Example

const params = {
  files: [{
    name: 'xxx',
    type: 'pdf',
    url: 'http://xxxx/xxx.pdf',
    header: {
      'custom-key': 'custom-value'
    }
  }]
}

edger.share.open(params).then(() => {
  console.log('share open successful')
}).catch(error => {
  console.error(error)
})

async / await

async function open(params) {
  try {
    await edger.share.open(params)
    console.log('share open successful')
  } catch (error) {
    console.error(error)
  }
}

Events

The unified event listener provided by Web-SDK:

const listener = (payload) => {
  // Event handling...
}

// add listener
edger.share.addEventListener('some-event', listener)

// or 
// onAction() is an alias of addEventListener().
edger.share.onAction('some-event', listener)

// remove listener
edger.share.removeEventListener('some-event', listener)

// remove all listeners
edger.share.removeAllListeners()

status

This event will be generated when the media sharing changes.

  • Returns: {Object} A share object.

Get an object of result, the object includes:

  • status {string} The share status. Optional values: open | cancel | success | fail.
  • message {string} The share details.

Example

edger.share.addEventListener('status', (payload) => {
  const { status, message} = payload;
  console.log("share status:", status, message)
})
文档内容是否对您有所帮助?
有帮助
没帮助