Search code examples
androidcordovacalllogminimized

How to display local notification when PhoneGap application is minimized


I have a PhoneGap application where I am using Background Service, PhoneListner and CallLog plugins for Android. So when ever there is an incoming/outgoing call ends, my application shows the notification having the last call details. But if I minimize the app then it is not showing the notification automatically. So I need to open the app to see the notification.

So is there any way to show the notification automatically when the application is minimized.


Solution

  • You can use the local notification plugin to achieve this. Its works perfectly even if you app is minimized.

    Here is the link https://github.com/zhuochun/local-notification

    You can follow the steps to add the plugin as stated in readme

    <script type="text/javascript">
    var notification = cordova.require("cordova/plugin/localNotification")
    
    document.addEventListener("deviceready", appReady, false);
    
    function appReady() {
      console.log("Device ready");
    
      notification.add({
          id: 1,
          date: new Date(),
          message: "Phonegap - Local Notification",
          subtitle: "Subtitle is here",
          ticker: "This is a sample ticker text",
          repeatDaily: false
      });
    }
    </script>
    

    Try this plugin.