1.1 接口声明
{"name": "system.share"}
1.2 导入模块
import share from '@system.share' 或 var share = require("@system.share")
1.3 share.share(OBJECT)
分享数据到其他app。
参数
| 参数 | 类型 | 必填 | 说明 |
| type | String | 是 | 数据的MIME TYPE,要求字母全小写。 |
| data | String | 是 | 分享的数据。 ● 如果type是text/开头的mimetype(如text/plain),则data是要分享的文本内容 ● 如果type是其他值,则data是要分享的文件路径 支持三种文件路径: ● 通过fetch.fetch下载的文件路径 ● 通过file.save或list获得的文件路径 ● 以/开头的应用内部的资源文件 |
| success | Function | 否 | 成功回调。因为大部分android app都没有正确的返回分享状态,所以即使分享成功了,也可能执行cancel回调,而不是success回调。 |
| fail | Function | 否 | 失败回调。 |
| cancel | Function | 否 | 取消回调。 |
| complete | Function | 否 | 执行结束后的回调。 |
示例
share.share({
type:"text/html",
data:"bold",
success:function(data){console.log("handling success");}
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
});
2 弹窗
2.1 接口声明
{"name": "system.prompt"}
2.2 导入模块
import prompt from '@system.prompt' 或 var prompt = require("@system.prompt")
2.3 prompt.showToast(OBJECT)
显示Toast。
参数
| 参数 | 类型 | 必填 | 说明 |
| message | String | 是 | 要显示的文本。 |
| duration | Number | 否 | 0为短时,1为长时,默认0。 |
示例
prompt.showToast({
message:'message'
})
2.4 prompt.showDialog(OBJECT)
显示对话框。
参数
| 参数 | 类型 | 必填 | 说明 |
| title | String | 否 | 标题。 |
| message | String | 否 | 内容。 |
| buttons | Array | 否 | 按钮的数组,按钮结构:{text:'text',color:'#333333'},color可选:buttons的第1项为positive button;buttons的第2项(如果有)为negative button;buttons的第3项(如果有)为neutral button。最多支持3个button。 |
| success | Function | 否 | 成功回调,返回值如表2-1所示。 |
| cancel | Function | 否 | 取消回调。 |
| complete | Function | 否 | 执行结束后的回调。 |
表2-1 success返回值
| 参数名 | 类型 | 说明 |
| index | Number | 选中按钮在buttons数组中的序号。 |
示例
prompt.showDialog({
title: 'title',
message: 'message',
buttons: [
{
text: 'btn',
color: '#33dd44'
}
],
success: function(data) {
console.log("handling callback");
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
})
2.5 prompt.showContextMenu(OBJECT)
显示上下文菜单。
参数
| 参数 | 类型 | 必填 | 说明 |
| itemList | Array | 是 | 按钮的文字数组。 |
| itemColor | HexColor | 否 | 按钮颜色。 |
| success | Function | 否 | 成功回调,返回值如表2-2所示。 |
| cancel | Function | 否 | 取消回调。 |
| complete | Function | 否 | 执行结束后的回调。 |
表2-2 success返回值
| 参数名 | 类型 | 说明 |
| index | Number | 选中按钮在itemList数组中的序号 |
示例
prompt.showContextMenu({
itemList: ['item1', 'item2'],
itemColor: '#ff33ff',
success: function(data) {
console.log("handling callback");
},
cancel: function() {
console.log("user cancel=");
}
})
3 打开网页
3.1 接口声明
{"name": "system.webview"}
3.2 导入模块
import webview from '@system.webview' 或 var webview = require("@system.webview")
3.3 webview.loadUrl(OBJECT)
打开网页,标题栏样式与打开webview的页面的标题栏样式相同,在webview的useragent后追加内容,格式是hap/<平台版本号>/<厂商标识> <平台应用包名>/<平台应用版本号> <应用包名>/<应用版本号> (<来源信息>)。“来源信息”与app接口的getInfo方法返回结果中的source字段相同。
参数
| 参数 | 类型 | 必填 | 说明 |
| url | String | 是 | 要加载的页面url |
示例
webview.loadUrl({
url:'http://www.example.com'
})
3.4 system.go(path)
WebView内部API,在webview打开的网页中可以使用的api。跳转到当前应用的指定页面。
参数
| 参数 | 类型 | 必填 | 说明 |
| path | String | 是 | 要跳转的页面,例:/detail?param1=value1特殊的,如果path的值是"/",则跳转到path为"/"的页,没有则跳转到首页。 |
示例
system.go("/detail?param1=value1")
4 通知消息
4.1 接口声明
{"name": "system.notification"}
4.2 导入模块
import notification from '@system.notification' 或 var notification = require("@system.notification")
4.3 notification.show(OBJECT)
显示通知。
参数
| 参数 | 类型 | 必填 | 说明 |
| contentTitle | String | 否 | 标题 |
| contentText | String | 否 | 内容 |
| clickAction | Object | 否 | 通知点击后触发动作的信息 |
表4-1 clickAction说明
| 参数名 | 类型 | 必填 | 说明 |
| uri | String | 是 | 点击通知后跳转的页面地址。支持的格式包括: 1. 以"/"开头的应用内页面的路径;例:/about 2. 以非"/"开头的应用内页面的名称;例:About 3. 特殊的,如果uri的值是"/",则跳转到path为"/"的页,没有则跳转到首页 可以通过“?param1=value1”的方式添加参数,参数可以在页面中通过this.param1的方式使用 |
示例
notification.show({
contentTitle:'title',
clickAction: {
uri:'/index.html?index=1'
}
})
5 震动
5.1 接口声明
{"name": "system.vibrator"}
5.2 导入模块
import vibrator from '@system.vibrator' 或 var vibrator = require("@system.vibrator")
5.3 vibrator.vibrate()
触发震动,持续1秒。
参数
无。
示例
vibrator.vibrate()





































苏公安网备 32011402010933号