Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top