Android的GCM(推送通知):如果应用程序已停止设备没有收到通知 [英] Android GCM (push notification): device doesn't receive notification if application is stopped

查看:583
本文介绍了Android的GCM(推送通知):如果应用程序已停止设备没有收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid项目使用推送通知(GCM)。

据GCM教程中,我实现广播接收器和的Andr​​oidManifest.xml 注册它。

这类型的广播接收机应接收消息,即使我的应用程序被关闭(不只是如果我的应用程序是在后台,但即使是力停止)。

但是,如我所料不工作。 的onReceive()方法不被当应用程序被关闭调用。看来,我的广播接收机的理解是正确的,问题是在我的预料约GCM。

其中一个可能的原因是,谷歌服务器甚至不发送通知给所述设备,如果该应用程序被关闭。那么,是不是很正确,我的应用程序能够接收消息(和的onReceive()方法将在广播接收器调用的)只有当它的运行还是在后台(但不封闭) ?

在此先感谢。

解决方案
  

这类型的广播接收机应接收消息,即使我的应用程序被关闭(不只是如果我的应用程序是在后台,但即使是力停止)。

如果用户从设置强制停止您的应用程序,你的code将永远不会再次运行,直到有手动运行的组件之一,通常是用户手动启动的活动(如安卓3.1)。因此,如果用户在设置强制停止您的应用程序,你会不会在较新的设备/仿真器接收GCM消息。

  

那么,是不是很正确,我的应用程序能够接收消息(和的onReceive()方法将在广播接收器调用的)只有当它的运行还是在后台(而不是封闭的)?

目前在Android的封闭没有从应用的角度来看的概念。如果由封闭,你的意思是没有正在运行的进程,其中最后一个进程被终止正常,那么,你应该得到GCM消息和其他节目。但是,再次发力,停止不正常终止。

I use push notification (GCM) in my Android project.

According to GCM tutorial I implemented broadcast receiver and registered it in AndroidManifest.xml.

This kind of broadcast receivers should receive messages even if my app is closed (not only if my app is in background but even if it was force stopped).

But it doesn't work as I expect. onReceive() method isn't being called if the app is closed. It seems that my understanding of broadcast receivers is correct and the problem is in my expectations about GCM.

One of the possible reasons is that google server doesn't even send a notification to the device if the app is closed. So, is it correct that my app can receive a message (and onReceive() method will be invoked in broadcast receiver) only if it's running or in background (but not closed)?

Thanks in advance.

解决方案

This kind of broadcast receivers should receive messages even if my app is closed (not only if my app is in background but even if it was force stopped).

If a user force-stops your app from Settings, your code will never ever run again, until something manually runs one of your components, typically the user manually launching an activity (as of Android 3.1). Hence, if the user force-stops your app from Settings, you will not receive GCM messages on newer devices/emulators.

So, is it correct that my app can receive a message (and onReceive() method will be invoked in broadcast receiver) only if it's running or in background (but not closed)?

There is no concept of "closed" in Android from an application standpoint. If, by "closed", you mean "has no running process, where the last process was terminated normally", then yes, you should receive GCM messages and other broadcasts. But, again, force-stop is not "terminated normally".

这篇关于Android的GCM(推送通知):如果应用程序已停止设备没有收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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