3

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.

sourav
  • 676
  • 5
  • 21
  • notifications to the user when the app is closed is AFAIK only possible with the Google Cloud Messaging Service (GCM) for Android. This is possible because the notification is fired remotely by a server you will have to maintain yourself. – 最白目 Mar 08 '13 at 09:43
  • Thanks for the reply. But i need the local notification not the push notification from GCM. – sourav Mar 08 '13 at 09:47
  • when the user´s phone is empty and he turns it on again after charging and doesnt open your app, the notification will never fire without GCM. – 最白目 Mar 08 '13 at 09:49

2 Answers2

1

You will have to create an Service that does the work in the background. A PhoneGap app is paused when it is 'minimized'.

I use this plugin, and it works awesome! https://github.com/Red-Folder/Cordova-Plugin-BackgroundService

In the Java part of the plugin (native Android code) you will have to program to check for calls and show a notification after. You can manage your service with the plugin from your PhoneGap app. I used it in my app to check for updates on my webserver.

1

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.

Ashis Kumar
  • 6,494
  • 2
  • 21
  • 36
  • This does not solve the problem at hand. When the app is in the background, notifications are silently ignored and nothing is shown. – andreszs Dec 29 '14 at 01:57