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发布的通知。持续关注中

 

声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
随机推荐
WordPress 文章排序
JavaScript 中 0.1 加 0.2 不等于 0.3 的原因和解决方法
JavaScript 操作 cookie
JavaScript history对象
Page Visibility API
JavaScript API 接口
Node.js http 模块
JavaScript 操作表单