我使用 Phonegap 开发了一个 Web 应用程序,它使用 Rss feed ="nofollow">Google-Feed API 并在有新 Feed 可用时向用户发送系统通知。
我使用了这个 Phonegap 系统通知插件来创建推送通知。
这是插件附带的 SystemNotificaton.java。
这是插件附带的 SystemNotification.js 文件,里面有你的 javascript 中可以使用的所有方法文件。
这是我的 notification.js javascript 文件,我创建了两个函数来读取两个单独的 Rss feed url,并且我使用了setIntervals 每 1 分钟调用一次该函数。我还在同一函数内调用了 navigator.systemNotification.onBackground(); 方法,以便当我的应用程序未处于活动状态时,该函数会在背景并在出现新提要时向用户显示通知。
问题是,一旦应用程序启动,我就会收到通知,然后当我关闭应用程序时,我会收到更多通知,一两天后,通知就会停止出现。我知道因为我使用的是 google-feed api 它不是实时的,但即使在两天后它仍然不起作用。看起来 onbackground 方法不起作用。谁能指出我犯了什么错误。
I have developed a Web application using Phonegap which reads cross domain Rss feeds using Google-Feed API and sends system notification to the user if a new feed is available.
I have used this Phonegap System Notification Plugin for creating push notifications.
This is the SystemNotificaton.java that comes with the plugin.
This is the SystemNotification.js file that comes with the plugin, which has all the methods that can be used in your javascript file.
This is my notification.js javascript file were I have created two functions to read two separate Rss feed urls and I have used setIntervals to call the function every 1 min.I have also called navigator.systemNotification.onBackground(); method inside the same function so that when my app is not active this function keeps running in the background and displays the notification to the user if a new feed comes up.
The problem is I get notifications once the application starts then when i close the application I get a couple of more, after one or two days the notification stops coming. I know since I am using google-feed api it is not real time but still even after two days it does not work . It seems like the onbackground method it not working. Could anyone point out what mistake I am doing.
发布评论
评论(1)
我对 Phonegap 不太了解,但我对 Android 开发了解很多,而且在我看来,通知不是你的问题。 (顺便说一句,这些只是通知,而不是“推送”通知。这些完全是另一头野兽。)
我怀疑您的应用程序只是停止了,并且您没有设置任何内容来启动它备份。 Android 操作系统会出于多种原因杀死任何后台应用程序。如果作为服务实现,操作系统应该在某个时候重新启动它,但这并不完全可靠。
基本上,您需要设置一个警报来照顾您的服务并确保它保持活动状态。如果这在 PhoneGap 中可行,我建议完全摆脱 setInterval,而仅使用闹钟来唤醒您的应用程序并触发 RSS 轮询操作。这样做的好处是当设备进入睡眠状态时它仍然可以工作。
快速搜索一下似乎表明 PhoneGap 无法访问 AlarmManager。也许可以通过插件来完成,但总体而言,PhoneGap 并不是一个很好的后台服务框架。真正的本机应用程序在这种情况下会表现得更好。
I don't know much about Phonegap, but I know a fair bit about Android development, and it sounds to me like the notifications aren't your problem. (Incidentally, these are just notifications, not "Push" notifications. Those are another beast altogether.)
I suspect that your application is simply stopping, and you don't have anything set to start it back up. The Android OS will kill any background application for a variety of reasons. If implemented as a service, the OS is supposed to restart it at some point, but that's not entirely reliable.
Basically, you need to set an alarm to babysit your service and make sure it stays alive. If this is possible in PhoneGap, I recommend getting rid of the setInterval altogether, and just using the alarm to wake your app up and trigger the RSS polling action. The benefit of this is that it will still work when the device goes to sleep.
Doing a bit of quick searching seems to indicate that PhoneGap does not have access to the AlarmManager. It could be done with a plugin, maybe, but PhoneGap doesn't strike me as a good framework for background services in general. A truly native app is going to be far better behaved in this context.