phonegap常用插件(更新)

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 name
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);//文件名
options.mimeType = "image/jpeg";//文件格式,默認爲image/jpeg

var 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 block
			e.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));  
    }  
  
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章