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对象内容
页面截图
测试操作系统
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
VS生成Cordova for Android应用之Gradle
原文: VS生成Cordova for Android应用之Gradle 一、Gradle简介 Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化建构工具。它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的各种繁琐配置。 在使用VS生成Cordova应用时,会自动下载Gradle到用户文件夹。 确认%UserProfile%(就是C:\Users\{userName})目录下有没有.gradle文件夹,没有的话,新建一个。 更多参考: Ionic Grid栅格布局居中实例 Ionic相关整理 http://www.cnblogs.com/slmk/p/5287936.html AndroidStudio中配置:http://blog.csdn.net/wiseclown/article/details/51088583
- 下一篇
iOS App 签名原理
https://mp.weixin.qq.com/s?__biz=MzA3NTYzODYzMg==&mid=2653578788&idx=1&sn=5d7c1f66c9df1a73eda80b150990bdfa&chksm=84b3b423b3c43d351d9fbe400e38d6682644b839e7385b1d21cb49bceb19026781c7bbb96732&mpshare=1&scene=23&srcid=0505GwKDYEmWa2wrCX1Iaxjq%23rd
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果