应用程序停止时如何从 GCM 接收通知 [英] How can I receive notifications from GCM when application is stopped

查看:22
本文介绍了应用程序停止时如何从 GCM 接收通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCMIntentService(扩展 GCMBaseIntentService)在应用程序未运行时不会收到通知.

来自:http://developer.android.com/about/versions/android-3.1.html

对停止的应用程序启动控制请注意,系统将 FLAG_EXCLUDE_STOPPED_PACKAGES 添加到所有广播意图.这样做是为了防止来自后台服务的广播无意中或不必要地启动已停止应用程序的组件.后台服务或应用程序可以通过将 FLAG_INCLUDE_STOPPED_PACKAGES 标志添加到应该允许激活已停止应用程序的广播意图来覆盖此行为.

有没有办法绕过这个设置?谢谢

解决方案

GCMIntentService(扩展 GCMBaseIntentService)在应用程序未运行时不会收到通知.

是的,会的.不过,您的其余问题与应用程序是否正在运行无关,而是与用户之前是否运行过有关.您引用的段落中停止"一词的含义不是未运行",而是表示应用程序所处的状态:

  • 首次安装时,在手动调用组件之前(例如,用户启动活动)

  • 在用户强制停止应用后,直到手动调用组件(例如,用户启动活动)

(我真的希望他们为此想出一个比停止"更独特的形容词......)

<块引用>

有没有办法绕过这个设置?

没有.如果用户强制停止您的应用程序,则表明他们不希望您的应用程序再次运行,无论出于何种原因,直到他们再次手动启动它.你的目标是让用户没有理由强行停止你的应用程序.请注意,我的意思是强制停止"(即按设置"中的强制停止"按钮)——普通的任务管理器,或者从 Android 4.x 中的近期任务"列表中滑动,没有这种效果.

GCMIntentService (extends GCMBaseIntentService) doesn't receive notifications if the application is not running.

From : http://developer.android.com/about/versions/android-3.1.html

Launch controls on stopped applications Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.

Is there a way to get around this setting? Thanks

解决方案

GCMIntentService (extends GCMBaseIntentService) doesn't receive notifications if the application is not running.

Yes, it will. The rest of your question, though, has little to do with whether the application is running, but rather whether it has been run by the user before. What the word "stopped" means in the paragraph you quote is not "not running", but represents a state that an application is in:

  • when it is first installed, before something manually invokes a component (e.g., user launches an activity)

  • after the user force-stops the app, until something manually invokes a component (e.g., user launches an activity)

(and I really really wish they had come up with a more distinctive adjective than "stopped" for this...)

Is there a way to get around this setting?

No. If the user force-stops your app, they are indicating that they do not want your app to run again, for any reason, until they manually launch it again. Your objective is to give the user no reason to force-stop your app. Note that I do mean "force-stop" (i.e., press the "Force Stop" button from Settings) -- ordinary task managers, or swiping from the Recent Tasks list in Android 4.x, does not have this effect.

这篇关于应用程序停止时如何从 GCM 接收通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆