目录

$device

$device是获取设备信息的服务对象

$device.getTimeZoneID()

获取时区ID

语法

  1. $device.getTimeZoneID();

$device.getTimeZoneDisplayName()

获取时区DisplayName

语法

  1. $device.getTimeZoneDisplayName();

$device.getLocation()

获取位置信息(此方法通过高德地图获取位置,使用时请先参照《DSL控件指南-高级-高德地图》配置应用签名-keystore

语法

  1. $device.getLocation({
  2. "bindfield" : "location", //位置信息回写的绑定字段
  3. "callback" : "getLocationCallBack()", //回调执行的JS方法
  4. "single" : "true", //是否只获取1次
  5. "isgetaddress" : "true", //是否需要获取地址
  6. "network" : "true" //是否使用wifi定位
  7. })

参数

  • bindfield:位置信息回写的绑定字段
  • callback:回调执行的JS方法
  • single:是否只获取1次
  • isgetaddress:是否需要获取地址
  • network:是否使用wifi定位

实例

  1. $device.getLocation({
  2. "bindfield" : "location",
  3. "callback" : function() {
  4. $alert($ctx.getString("location"));
  5. },
  6. "single" : "true",
  7. "isgetaddress" : "false",
  8. "network" : "false"
  9. });

$device.openWebView()

打开网页

语法

  1. $device.openWebView({
  2. "url" : "http://www.yyuap.com"
  3. });

参数

  • url:打开网页的URL

$device.getInternalMemoryInfo()

获取内部存储信息

语法

  1. $device.getInternalMemoryInfo()

$device.getExternalStorageInfo()

获取外部存储信息,该服务只针对Android

语法

  1. $device.getExternalStorageInfo();

$device.getMemoryInfo()

获取存储信息

语法

  1. $device.getMemoryInfo();

$device.getDeviceInfo()

获取设备信息

语法1:同步

  1. $device.getDeviceInfo();

语法2:异步

  1. $device.getDeviceInfo({
  2. "bindfield" : "dinfo", //信息回写的绑定字段
  3. "callback" : "getDeviceInfoCallBack()" //回调执行的JS方法
  4. })

$device.getScreenHeight()

获取手机屏幕的高度

语法

  1. $device.getScreenHeight();

$device.getScreenWidth()

获取手机屏幕的宽度

语法

  1. $device.getScreenWidth();

$device.getScreenDensity()

像素密度,通常是2或3

语法

  1. $device.getScreenDensity();

$device.notify()

提醒服务

语法

  1. $device.notify({
  2. "sendTime" : "2015-02-03 13:54:30", //提示时间
  3. "sendBody" : "您设置了消息提醒事件", //提示文字内容
  4. "icon" : "app.png"//图标
  5. })

$device.capturePhoto()

获取手机相册图片

语法

  1. $device.capturePhoto({
  2. "bindfield" : "image", //存放图片返回值的Context字段名
  3. "callback" : "capturePhotoCB()"//回调JS方法
  4. })

参数

  • bindfield:存储照片的字段
  • callback:回调

用法

  1. $device.capturePhoto({
  2. "bindfield" : "image", //存放图片返回值的Context字段名
  3. "callback" : function() {
  4. var img = $ctx.getString("image");
  5. $id("image0").set("src", img);
  6. }
  7. });

$device.recordedVideo()

录制(小)视频

语法

  1. $device.recordedVideo({
  2. "duration" : "10", //录制视频最大时长(上限15秒),单位秒
  3. "bindfield" : "recordedResult", //录制的结果,为JSON,格式参考下面的说明
  4. "callback" : "recordedVideoCB()"//回调JS方法
  5. })

参数

  • duration:录制视频最大时长(上限15秒),单位秒
  • bindfield:录制的结果,为JSON,格式参考下面的说明
  • callback:回调

用法

  1. $device.recordedVideo({
  2. "duration" : "10", //录制视频最大时长(上限15秒),单位秒
  3. "bindfield" : "recordedResult", //录制的结果,为JSON,格式参考下面的说明
  4. "callback" : function() {
  5. var recordedResult = $ctx.getString("recordedResult");
  6. $alert(recordedResult);
  7. }
  8. });

recordedResult值

  1. //拍照时
  2. {
  3. "recordedType":"image|video",
  4. "recordedImage":"图片路径",
  5. "thumbImage":"缩略图路径"
  6. }
  7. //录制视频时
  8. {
  9. "recordedType":"image|video",
  10. "recordedVideo":"视频路径",
  11. "thumbImage":"缩略图路径"
  12. }

$device.screenShot()

手机截屏服务

语法

  1. $device.screenShot({
  2. "bindfield" : "dinfo",
  3. "callback" : "xxx()"
  4. })

参数

  • bindfield:信息回写的绑定字段
  • callback:回调执行的js方法

用法

  1. function com$yonyou$aaa$Device117Controller$button13_onclick(sender, args) {
  2. $device.screenShot({
  3. "bindfield" : "dinfo", //信息回写的绑定字段
  4. "callback" : "getScreenShotCallBack()" //回调执行的JS方法
  5. })
  6. }
  7. function getScreenShotCallBack() {
  8. var info = $ctx.getString("dinfo");
  9. $id("image0").set("src", info);
  10. }

$device.saveContact()

把信息写入通讯录

语法

  1. $device.saveContact({
  2. "tel" : "139****", //手机号码
  3. "employeename" : "张三", //联系人名称
  4. "jobname" : "职员", //职位
  5. "orgname" : "开发部", //部门名称
  6. "address" : "北京市海淀区***", //单位地址
  7. "email" : "zhangsan@yonyou.com", //邮箱
  8. "officetel" : "6243****"//办公电话
  9. })

$device.openAddressBook()

打开通讯录

语法

  1. $device.openAddressBook();

$device.getContacts()

获取手机通讯录

语法

  1. $device.getContacts()

参数

实例

  1. var value=$device.getContacts();
  2. alert(value);

注意:使用此方法时,一定要在application.xml文件中权限页面,把允许访问联系人的权限勾上

$device.currentOrientation()

获取手机横竖屏状态,返回值为 “portrait” | “landscape”, 表示 横屏 or 竖屏

语法

  1. $device.currentOrientation()

参数

实例

  1. function com$requirement0724$OrientationController$change(sender, args) {
  2. var currentOrientation = $device.getContacts();
  3. if ( currentOrientation = "portrait") {
  4. }
  5. if ( currentOrientation = "landscape") {
  6. }
  7. }

$device.generateQRCode()

把字符串生成二维码

使用生成二维码相关服务需要先勾选二维码扫描插件,如下图操作:
****

语法

  1. $device.generateQRCode()

参数

  • twocode-size:二维码正方形的边长
  • twocode-content:生成二维码所需的字符串

实例

  1. function com$requirement0724$TwocodeImageController$onclick(sender, args) {
  2. var text = $id("textbox0").get("value");
  3. var len = $id("textbox1").get("value");
  4. var twocodepath = $device.generateQRCode({
  5. size : len, //二维码正方形的宽高
  6. content : text//生成二维码所需的源文字
  7. });
  8. $id("image0").set("src", twocodepath);
  9. }

$device.getAlbumPath()

获取相册路径 - Android独有

语法

  1. $device.getAlbumPath()
  2. $device.getAlbumPath({
  3. "allFolders" : true, //是否获取相册中所有文件夹
  4. "callback" : "mycallback()"
  5. })
  6. $device.getAlbumPath({
  7. "allFolders" : false, //是否获取相册中所有文件夹
  8. "callback" : "mycallback()"
  9. })

参数

  • 1、无参数
  • 2、json对象 - allFolders:true|false 是否获取设备相册中所有文件夹callback:xxx() 回调方法

返回值

  • callback的方法中args中存储获取的相册路径信息,通过args.result获取;
  • 当allFolders=true时,args.result为数组,获取的是设备相册中所有路径信息;
  • 当allFolders=false时,args.result获取的是设备系统相册的路径

实例

  1. var path = $device.getAlbumPath()//获取相册路径
  2. $device.getAlbumPath({
  3. "allFolders" : "true", //是否获取相册中所有文件夹
  4. "callback" : "getAlbumPathCB()"
  5. })
  6. function getAlbumPathCB(sender, args) {
  7. $alert(args.result);
  8. }
  9. $device.getAlbumPath({
  10. "allFolders" : "false", //是否获取相册中所有文件夹
  11. "callback" : "getAlbumPathCB()"
  12. })
  13. function getAlbumPathCB(sender, args) {
  14. $alert(args.result);
  15. }

$device.getAppAlbumPath()

获取相机服务存放照片的存储路径

语法

  1. $device.getAppAlbumPath()

实例

  1. var path =$device.getAppAlbumPath()//获取相机服务拍照的路径

$device.openApp()

打开app

语法:

  1. $device.openApp(json);

参数:

  • json
    • ios_appid :ios系统app的名称需要配置(配置文件位置 组件/Config/ios-config.xml)
    • android_packagename:安卓系统app的包名
    • params:参数
    • callback:回调执行的函数

示例:

  1. $device.openApp({
  2. "ios_appid" : "weixin",
  3. "android_packagename" : "com.tencent.mm",
  4. "param" : {},
  5. "callback" : "mycallback()"
  6. });

可用性:
iOS系统,Android系统

$device.openFlashLight()

打开闪关灯服务。

语法

  1. $device.openFlashLight()

实例

  1. $device.openFlashLight()//打开闪关灯

$device.closeFlashLight()

关闭闪光灯服务。

语法

  1. $device.closeFlashLight()

实例

  1. $device.closeFlashLight()//关闭闪关灯
文档更新时间: 2018-01-15 14:37