# Sharing
Data sharing with other apps.
# Manifest Declaration
You need to declare the use of this API in the manifest's features member:
{"name": "system.share"}
# Module Import
Before using this service in a component, you need to import the module in the script section of the UX document.
import share from '@system.share'
Or
let share = require("@system.share")
# Methods
This service has the following method:
# share({type,data,success,fail,cancel,complete})
This method enables the app to share data with other apps..
# Arguments
This method requires an object with the following attributes:
type(string). Mandatorystringwith the MIME type of the data to share (lowercase).data(string). Mandatorystringwith the data to share. The value can be of different types:- If the value of
typeis a MIME type starting bytext/(e.g.,,text/plain),datacontains the textual content to share. - Otherwise,
datamust contain the path of the file to be shared. The following file paths are supported:- Path of the file downloaded through
fetch.fetch(); - File path obtained through
file.save()orfile.list() - In-app resource file path starting with a slash character (
/).
- Path of the file downloaded through
- If the value of
success(function). Optional callback function corresponding to the successful execution.fail(function). Optional callback function corresponding to the failed execution.cancel(function). Optional callback function corresponding to the cancellation of the execution.complete(function). Optional callback function corresponding to the end of the execution.
Example:
share.share({
type: "text/html",
data: "<b>bold</b>",
success: function(data) { console.log("handling success"); },
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
});