標籤:ndt htm 測試 water scheduled document des dia rri
原文:cordova-plugin-local-notifications發送Android本地訊息
1.GitHub原始碼地址:
https://github.com/katzer/cordova-plugin-local-notifications
2.參數說明:
https://github.com/katzer/cordova-plugin-local-notifications/wiki/04.-Scheduling
3.事件說明:
https://github.com/katzer/cordova-plugin-local-notifications/wiki/09.-Events
4.使用執行個體:
一、Html代碼:
<ion-pane ng-app="notiTest" ng-controller="NotiCtrl"> <ion-header-bar class="bar-positive" align-title="center"> <h1 class="title">簡單訊息執行個體</h1> </ion-header-bar> <ion-content> <ion-list> <ion-item ng-click="sendOne()"> 發送單個訊息 </ion-item> <ion-item ng-click="sendTwo()"> 發送多個訊息 </ion-item> <ion-item ng-click="sendThree()"> 重複提醒 </ion-item> <ion-item ng-click="sendFourth()"> 帶參數方法 </ion-item> </ion-list> </ion-content></ion-pane><!-- Cordova 引用,它在產生應用程式時添加到其中。 --><script src="cordova.js"></script><script src="scripts/platformOverrides.js"></script><script src="scripts/ionic/js/ionic.bundle.min.js"></script><script src="scripts/index.js"></script>
二、js代碼
1.發送單個訊息
cordova.plugins.notification.local.schedule({ id: 1, title: ‘應用提醒‘, text: ‘應用新訊息,款來看吧‘, at: new Date().getTime(), badge: 2});//新版本使用 add 可以替換 schedulecordova.plugins.notification.local.add({ id: 1, title: ‘應用提醒‘, text: ‘應用新訊息,款來看吧‘, at: new Date().getTime(), badge: 2, autoClear: true,//預設值 sound: ‘res://platform_default‘,//預設值 icon: ‘res://ic_popup_reminder‘, //預設值 ongoing: false //預設值});//使用Uri定義icon、sound失敗,原因還沒有找到cordova.plugins.notification.local.add({ id: 1, title: ‘應用提醒~~~1‘, text: ‘應用新訊息,款來看吧‘, at: new Date().getTime(), badge: 2, //使用本地音頻失敗 sound: ‘file://permission.mp3‘, //起作用 //icon: ‘ic_media_play‘, //使用本體圖片失敗 icon: ‘file://images/g.jpg‘, //使用外網圖片失敗 //icon: "http://www.weilanliuxue.cn/Content/Images/Index2/h_index01.jpg",});
2.發送多個訊息
cordova.plugins.notification.local.schedule([{ id: 1, title: ‘應用提醒1‘, text: ‘應用提醒內容1‘, at: new Date()}, { id: 2, title: ‘應用提醒2‘, text: ‘應用提醒內容2‘, //目前時間延遲2秒 at: new Date(new Date().getTime() + 1000 * 3)}]);
3.發送重複訊息
cordova.plugins.notification.local.schedule({ title: ‘重複訊息標題‘, text: ‘重複訊息內容‘, at: new Date(), every: ‘minute‘});
4.發送帶參數訊息
cordova.plugins.notification.local.schedule({ id: 1, title: ‘帶參數‘, text: ‘內容‘, firstAt: new Date(new Date().getTime() + 2 * 1000), every: ‘minute‘, data: { meetingID: ‘1324‘, time: new Date() }});
5.事件監聽
//shedule事件在每次調用時觸發cordova.plugins.notification.local.on(‘schedule‘, function (notification) { alert(‘scheduled:‘ + notification.id);});//通知觸發事件cordova.plugins.notification.local.on(‘trigger‘, function (notification) { //alert(‘triggered:‘ + notification.id); alert(JSON.stringify(notification));});//監聽點擊事件cordova.plugins.notification.local.on(‘click‘, function (notification) { alert(JSON.stringify(notification)); document.getElementById(‘title‘).innerHTML = JSON.stringify(notification.data);});
notification對象內容
頁面
測試作業系統
cordova-plugin-local-notifications發送Android本地訊息