phonegap常用插件(更新)

来源:互联网 发布:jquery数组长度 编辑:程序博客网 时间:2024/05/01 09:18
Access files on device or network 访问本地或网络文件:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git

phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git

var options = new FileUploadOptions(); //文件参数选项options.fileKey = "file";//向服务端传递的file参数的parameter nameoptions.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);//文件名options.mimeType = "image/jpeg";//文件格式,默认为image/jpegvar ft = new FileTransfer();//文件上传类ft.onprogress = function (progressEvt) {//显示上传进度条if (progressEvt.lengthComputable) {navigator.notification.progressValue(Math.round(( progressEvt.loaded / progressEvt.total ) * 100));}}navigator.notification.progressStart("提醒", "当前上传进度");ft.upload(imageURI, encodeURI(pre_url+"/senyuanmespda/qc/product/uploadPhoto.do?serialNo="+serialNo), function () {navigator.notification.progressStop();//停止进度条navigator.notification.alert("文件上传成功!", null, "提醒");}, null, options);


Camera, media capture, and media playback 摄像头
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git

navigator.camera.getPicture


Basic device information 基本设备信息:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

Notifications via dialog box or vibration 提示框通知或震动:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration.git
navigator.notification.alert


barcodescanner二维码扫描
phonegap local plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git

cordova.plugins.barcodeScanner.scan

jpush极光推送

phonegap local plugin add https://github.com/jpush/jpush-phonegap-plugin.git

package com.sygroup;import java.util.HashMap;import java.util.Map;import cn.jpush.api.JPushClient;import cn.jpush.api.common.resp.APIConnectionException;import cn.jpush.api.common.resp.APIRequestException;import cn.jpush.api.push.PushResult;import cn.jpush.api.push.model.PushPayload;import cn.jpush.api.report.MessagesResult;public class TestJpush {private static final String appKey ="f65c228e4bc309efba5c7faf";    //必填,例如466f7032ac604e02fb7bda89        private static final String masterSecret = "98c6661d98a70a8861143f19";//"13ac09b17715bd117163d8a1";//必填,每个应用都对应一个masterSecret        private static JPushClient jpush = null;        /**      * 保存离线的时长。秒为单位。最多支持10天(864000秒)。      * 0 表示该消息不保存离线。即:用户在线马上发出,当前不在线用户将不会收到此消息。      * 此参数不设置则表示默认,默认为保存1天的离线消息(86400秒)。      */      private static long timeToLive =  60 * 60 * 24;          public static void main(String[] args) {          /*          * Example1: 初始化,默认发送给android和ios,同时设置离线消息存活时间          * jpush = new JPushClient(masterSecret, appKey, timeToLive);          */            /*                * Example2: 只发送给android          * jpush = new JPushClient(masterSecret, appKey, DeviceEnum.Android);          */            /*          * Example3: 只发送给IOS          * jpush = new JPushClient(masterSecret, appKey, DeviceEnum.IOS);          */            /*          * Example4: 只发送给android,同时设置离线消息存活时间          * jpush = new JPushClient(masterSecret, appKey, timeToLive, DeviceEnum.Android);          */          jpush = new JPushClient(masterSecret, appKey, 3);  System.out.println(jpush);          /*          * 是否启用ssl安全连接, 可选          * 参数:启用true, 禁用false,默认为非ssl连接          */          //jpush.setEnableSSL(true);              //测试发送消息或者通知          testSend();      }          public static PushPayload buildPushObject_all_all_alert(){    return PushPayload.alertAll("come on boy");//    return PushPayload.messageAll("message ");    }      private static void testSend() {          // 在实际业务中,建议 sendNo 是一个你自己的业务可以处理的一个自增数字。          // 除非需要覆盖,请确保不要重复使用。详情请参考 API 文档相关说明。          int sendNo = getRandomSendNo();          String msgTitle = "+;//jpush\"\"";          String msgContent = "\\&;w\"\"a--【\npush】";            PushPayload payload = buildPushObject_all_all_alert();        /*          * IOS设备扩展参数,          * 设置badge,设置声音          */            Map<String, Object> extra = new HashMap<String, Object>();  //        iosExtra iosExtra = new IOSExtra(10, "WindowsLogonSound.wav");  //        extra.put("ios", iosExtra);            //对所有用户发送通知, 更多方法请参考文档  //        MessagesResult msgResult = jpush.sendCustomMessageWithAppKey(sendNo,msgTitle, msgContent);          PushResult msgResult=null;try {msgResult = jpush.sendPush(payload);} catch (APIConnectionException | APIRequestException e) {// TODO Auto-generated catch blocke.printStackTrace();}        //MessageResult msgResult  = jpush.sendNotificationWithAlias(sendNo, "a", msgTitle, msgContent);            //覆盖指定msgId的消息,msgId可以从msgResult.getMsgid()获取。          //MessageResult msgResult = jpush.sendNotificationWithAppKey(sendNo, msgTitle, msgContent, 0, extra,msgResult.getMsgid());              if (null != msgResult) {              System.out.println("服务器返回数据: " + msgResult.toString());              if (msgResult.isResultOK()) {                  System.out.println(String.format("发送成功, sendNo= %s,messageId= %s",msgResult.sendno,msgResult.msg_id));              } else {                  System.out.println("发送失败, 错误代码=" + msgResult.ERROR_MESSAGE_NONE + ", 错误消息=" + msgResult.ERROR_MESSAGE_NONE);              }          } else {              System.out.println("无法获取数据");          }        }        public static final int MAX = Integer.MAX_VALUE;      public static final int MIN = (int) MAX/2;        /**      * 保持 sendNo 的唯一性是有必要的      * It is very important to keep sendNo unique.      * @return sendNo      */      public static int getRandomSendNo() {          return (int) (MIN + Math.random() * (MAX - MIN));      }    }


0 0