文档开发者中心
我的

<如何开发快应用 6>API 界面

1 分享
1.1 接口声明
{"name": "system.share"}   

1.2 导入模块
import share from '@system.share' 或 var share = require("@system.share")   

1.3 share.share(OBJECT)
       分享数据到其他app。
参数
参数类型必填说明
typeString是数据的MIME TYPE,要求字母全小写。
dataString是分享的数据。
● 如果type是text/开头的mimetype(如text/plain),则data是要分享的文本内容
● 如果type是其他值,则data是要分享的文件路径
支持三种文件路径:
● 通过fetch.fetch下载的文件路径
● 通过file.save或list获得的文件路径
● 以/开头的应用内部的资源文件
successFunction否成功回调。因为大部分android app都没有正确的返回分享状态,所以即使分享成功了,也可能执行cancel回调,而不是success回调。
failFunction否失败回调。
cancelFunction否取消回调。
completeFunction否执行结束后的回调。

示例
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。
参数
参数类型必填说明
messageString是要显示的文本。
durationNumber否0为短时,1为长时,默认0。

示例
prompt.showToast({
  message:'message'
})
   


2.4 prompt.showDialog(OBJECT)
       显示对话框。
参数
参数类型必填说明
titleString否标题。
messageString否内容。
buttonsArray否按钮的数组,按钮结构:{text:'text',color:'#333333'},color可选:buttons的第1项为positive button;buttons的第2项(如果有)为negative button;buttons的第3项(如果有)为neutral button。最多支持3个button。
successFunction否成功回调,返回值如表2-1所示。
cancelFunction否取消回调。
completeFunction否执行结束后的回调。

       表2-1 success返回值

参数名类型说明
indexNumber选中按钮在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)
       显示上下文菜单。
参数
参数类型必填说明
itemListArray是按钮的文字数组。
itemColorHexColor否按钮颜色。
successFunction否成功回调,返回值如表2-2所示。
cancelFunction否取消回调。
completeFunction否执行结束后的回调。

       表2-2 success返回值

参数名类型说明
indexNumber选中按钮在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字段相同。
参数
参数类型必填说明
urlString是要加载的页面url

示例
webview.loadUrl({
  url:'http://www.example.com'
})
   


3.4 system.go(path)
       WebView内部API,在webview打开的网页中可以使用的api。跳转到当前应用的指定页面。
参数
参数类型必填说明
pathString是要跳转的页面,例:/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)
       显示通知。
参数
参数类型必填说明
contentTitleString否标题
contentTextString否内容
clickActionObject否通知点击后触发动作的信息

       表4-1 clickAction说明

参数名类型必填说明
uriString是点击通知后跳转的页面地址。支持的格式包括:
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()   

点赞
收藏
回复
分享
举报
浏览1276 发布于2018-05-03 02:31未知归属地
全部评论
最多点赞
最新发布
最早发布
暂无评论
暂无评论
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。