Cordova 非官方插件 cordova-plugin-local-notifications 通知

获取系统通知插件,github上星数最多的。
https://github.com/katzer/cordova-plugin-local-notifications

1. 安装 
cordova plugin add cordova-plugin-local-notifications
安装失败,貌似是源问题,切换了npm源也还是失败。 地址是.de开头的。  

使用下面命令安装成功:

# cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
Installing "cordova-plugin-local-notification" for android
android-sdk version check failed ("/Users/ice/workspace/Apps/test/platforms/android/cordova/android_sdk_version"), continuing anyways.
Plugin dependency "cordova-plugin-device@2.0.2" already fetched, using that version.
Dependent plugin "cordova-plugin-device" already installed on android.
Installing "cordova-plugin-badge" for android
Android Studio project detected
Subproject Path: CordovaLib
Subproject Path: app
Subproject Path: CordovaLib
Subproject Path: app
Adding cordova-plugin-local-notification to package.json
Saved plugin info for "cordova-plugin-local-notification" to config.xml

2. build 错误
Unexpected inputs: ImmutableJarInput{name=com.android.support:support-annota...

clean
build

3. 使用方法查看
https://github.com/katzer/cordova-plugin-local-notifications
https://github.com/katzer/cordova-plugin-local-notifications/tree/example-x

4. 示例代码

cordova.plugins.notification.local.schedule({
    title: '我的第一个系统通知',
    text: 'Bybird APP 是个好东西,真棒...',
    foreground: true
});
cordova.plugins.notification.local.schedule({
    title: '又来系统通知了',
    text: 'Bybird APP 是个好东西,真棒...',
    foreground: true
});
cordova.plugins.notification.local.schedule([{
    id: 1,
    text: 'Multi Message 1',
    icon: 'res://cordova'
}, {
    id: 2,
    text: 'Multi Message 2',
    icon: 'res://icon',
    smallIcon: 'ic_media_play'
}, {
    id: 3,
    text: 'Multi Message 3',
    icon: 'res://icon',
    smallIcon: 'ic_media_pause'
}]);

cordova.plugins.notification.local.hasPermission(function (granted) {
    alert(granted ? 'Yes' : 'No');
});
cordova.plugins.notification.local.getScheduled(function (nots) {
    alert("All "+JSON.stringify(nots));
});

// Get all notification ids
cordova.plugins.notification.local.getIds(function (ids) {
    alert("All " + JSON.stringify(ids));
});
// Get all notification ids
cordova.plugins.notification.local.getScheduledIds(function (ids) {
    alert("All " + JSON.stringify(ids));
});
// Get all notification ids
cordova.plugins.notification.local.getTriggeredIds(function (ids) {
    alert("All " + JSON.stringify(ids));
});
// Get all scheduled notifications
cordova.plugins.notification.local.getScheduled(function (nots) {
    alert("All " + JSON.stringify(nots));
});
// Get all triggered notifications
cordova.plugins.notification.local.getTriggered(function (nots) {
    alert("All " + JSON.stringify(nots));
});
// Get a single notification
cordova.plugins.notification.local.get(1, function (obj) {
    alert("All " + JSON.stringify(obj));
});
// Get multiple notifications
cordova.plugins.notification.local.get([1, 2], function (nots) {
    alert("All " + JSON.stringify(nots));
});
// Get all notifications
cordova.plugins.notification.local.getAll(function (nots) {
    alert("All " + JSON.stringify(nots));
});

 

5. 貌似这个只能获取自己发布的通知,不能获取其他App发布的通知。持续关注中

 

修改时间 2019-07-02

真诚赞赏,手留余香
赞赏
随机推荐
Windows 下 Redis 安装配置 PHP 模块
子元素margin-top对父元素的影响
mysql无法启动ERROR! MySQL is running but PID file could not be found
npm warn package.json @1.0.0 no repository field
该不该删除数据——关于软删除
mint-ui中的cell无法绑定原生事件
Node.js i18n 国际化实现语言切换
DedeCMS 如何使用文章列表序号
发送header文件头信息实现文件下载
babel-preset-env 一个就够了