大家好(如果这个问题已经回答但对我没有任何作用,我很抱歉)。
我正在开发一个带有phonegap 3.1的android APP,我需要观察用户的位置并将其发送到服务器中。所有的通信都是用 javascript 完成的。
目前,我的应用程序运行良好,但是当它进入后台时,android 会随机杀死我的应用程序。我需要一些东西让我的应用程序留在后台。
我知道我可以使用后台服务,但我不知道我是否可以使用后台服务执行我的 javascript 函数。
我可以阅读的另一个问题是发出通知并在 startForeground() 中提供午餐,但在女巫服务中我可以在此 startForeground() 中提供午餐。目前我尝试了这个:
mNotificationManager.notify(tag.hashCode(), noti);
Service s = (Service) cordova.getActivity().getSystemService(ns);
s.startForeground(777, noti);
我也试试这个:
context = cordova.getActivity().getApplicationContext();
Notification noti = StatusNotificationIntent.buildNotification(context, tag, contentTitle, contentText, flag);
mNotificationManager.notify(tag.hashCode(), noti);
((Service) context).startForeground(777, noti);
但我知道这样做是错误的。
谢谢你未来的答案。