简体   繁体   English

为了接收通知,如何在Android上定期和以编程方式自动启动应用程序?

[英]In order to receive notifications, how to autostart app periodically and programmatically on Android?

I'm using FCM to send notifications to my users, unfortunately some manufacturers interfere with notifications delivery, according to this article: https://onesignal.com/blog/manufacturers-interfere-with-reliable-notifications/ 根据本文,我正在使用FCM向用户发送通知,不幸的是,一些制造商会干扰通知的发送: https : //onesignal.com/blog/manufacturers-interfere-with-reliable-notifications/

The problems comes up normally when users swipe off your app from the recent apps stack, since this cause a force stop on some devices. 当用户从最近的应用程序堆栈中滑出您的应用程序时,通常会出现问题,因为这会导致某些设备上的强制停止。

Thinking of a solution, I've noticed that when app is opened after a notification is sent (but it's not shown by phone), the notification finally is displayed... so, my suggested approach it's to launch my app ( in background ) periodically to ensure that notifications are delivered to my users. 考虑解决方案时,我注意到在发送通知后打开应用程序(但未通过电话显示),该通知最终会显示出来...因此,我建议的方法是在后台启动我的应用程序定期确保将通知传递给我的用户。

So.. my question: How can I launch my app on background programatically? 所以..我的问题:如何以编程方式在后台启动我的应用程序? Maybe posible with alarmManager , but not sure. 可能与alarmManager一起alarmManager ,但不确定。

Some related info on this thread: Android app not receiving Firebase Notification when app is stopped from multi-task tray 此线程上的一些相关信息: 从多任务托盘停止运行时,Android应用程序未收到Firebase通知

For this case that you described, if app is forced stoped when user swipe it out from recent apps, then no process of it will work anymore until the next time that user opens the app. 对于您所描述的这种情况,如果在用户从最近的应用程序中刷出某个应用程序时,该应用程序被迫停止运行,则直到下一次该用户打开该应用程序时,该应用程序的任何处理都将不再起作用。 It's the behaviour of force closing and you can not start app in background if it is forced closed. 这是强制关闭的行为,如果强制关闭,则无法在后台启动应用程序。 The app will receive notification when it is opened by user because notifications has a lifetime on GCM which can be up to 4 weeks and by default is set to 4 weeks. 该应用在用户打开时会收到通知,因为通知在GCM上的有效期最长为4周,默认情况下设置为4周。 So user will receive notification if opens his/her app sometime within this time to live interval. 因此,如果在此time to live间隔内某个time to live打开了他/她的应用,用户将收到通知。

For your case I suggest to show a guide to user at first run of application (specially for users of devices like Huawei, Asus and Xiaomi which have such settings as default) and encouraging them to exclude your app from those apps which are not allowed to work in background or access network in background. 对于您的情况,我建议在应用程序首次运行时向用户显示指南(特别是针对华为,华硕和小米等具有默认设置的设备的用户),并鼓励他们将您的应用程序从不允许运行的应用程序中排除在后台工作或在后台访问网络。 For example for some Huawei devices your app should be listed in Protected Apps and also be Networked Apps . 例如,对于某些华为设备,您的应用程序应列在“ Protected Apps ,也应列为“ Networked Apps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM