您现在的位置是:首页 > 文章详情

cordova-plugin-local-notifications发送Android本地消息

日期:2018-05-06点击:401
原文: 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 可以替换 schedule cordova.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对象内容


页面截图


测试操作系统


原文链接:https://yq.aliyun.com/articles/678779
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章