Giter Site home page Giter Site logo

notificationlistener-cordova's Introduction

NotificationListenerService plugin for Cordova

This is an implementation of the NotificationListenerService in Android for Cordova.

A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.

Note: This plugin doesn't work for IOS or Windows Phone, feel free to create a pull request if you want to add that functionality to this project.

How to install

cordova plugin add https://github.com/websixGmbH/NotificationListener-cordova

Enable notification listener service

This service requires an special permission that must be enabled from settings on Android (Settings > Notifications > Notification access)

Note: The app requires the following permission in your Manifest file on Android, which will be added automatically:

android.permission.BIND_NOTIFICATION_LISTENER_SERVICE

How to use

On Cordova initialization, add the callback for your notification-listener. Then everytime you get a notification in your phone that callback in JS will be triggered with the notification data.

var app = {
    initialize: function() {
       console.log("Initializing app");
       this.bindEvents();
    },
    bindEvents: function() {
        console.log("Binding events");
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    onDeviceReady: function() {
       console.log("Device ready");

       notificationListener.listen(function(n){
         console.log("Received notification " + JSON.stringify(n) );
       }, function(e){
         console.log("Notification Error " + e);
       });
    }
};
app.initialize();

For a full example, please see our WatchDuino2 repository

Sample output

Received notification
{
  "title":"Chuck Norris",
  "package":"com.google.android.talk",
  "text":"Hello world",
  "textLines":""
}

Notification response format

The notification response received by Javascript is a simplified object from the StatusBarNotification class in Android.

Feel free to update the notification parser inside this plugin if needed.

notificationlistener-cordova's People

Contributors

sneumannws avatar rephus avatar

Stargazers

Sven avatar

Watchers

James Cloos avatar Sven avatar David avatar Rafael Kraut avatar

Forkers

faisher jerwarren

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.