禁止广播接收器:在Android 3.1 GCM推送通知 [英] GCM push notifications on android 3.1 : disable broadcast receiver

查看:288
本文介绍了禁止广播接收器:在Android 3.1 GCM推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个与在Android 3.1的Andr​​oid推送通知(GCM)问题:当我的应用程序被关闭 - 广播接收机,它应该处理GCM推送消息(意图)不会被调用。

在较低版本的Andr​​oid一切工作得很好。广播reciever总是被调用(即使在应用程序被关闭)。

我知道,从安卓3.1有新的概念:当应用程序不运行它处于停止状态: <一href="http://developer.android.com/about/versions/android-3.1.html#launchcontrols">http://developer.android.com/about/versions/android-3.1.html#launchcontrols

所以,如果你想开始停止应用程序通过意图 - 你应该添加FLAG_INCLUDE_STOPPED_PACKAGES标志意向。

但问题是,我不能FLAG_INCLUDE_STOPPED_PACKAGES标志添加到GCM意图,因为GCM意图(我的意思是com.google.android.c2dm.intent.RECEIVE和com.google.android.c2dm.intent.REGISTRATION )由OS抛出。

所以我的问题是:如何处理我通过广播reciever的情况下推动从GCM的消息(在Android 3.1),当应用程序(其中BroadcastReceiver的登记)被关闭(处于停止状态)?

解决方案
  我

如何处理通过广播reciever的情况下推动从GCM的消息(在Android 3.1),当应用程序(其中BroadcastReceiver的登记)被关闭(处于停止状态)?

您不能。如果用户强制停止您的应用程序,没有您的应用程序将(在Android 3.1+)再次运行,除非手动调用,例如启动你的活动之一的用户。你的目标是让用户没理由逼停你的应用程序。

There is the problem with android push notifications (GCM) on android 3.1 : when my app is CLOSED - broadcast receiver which should handle GCM push messages (Intents) is never called.

In lower versions of android everything works just fine. Broadcast reciever is always called (even when app is closed).

I know that from Android 3.1 there is new concept: when application is not running it is in "stopped" state: http://developer.android.com/about/versions/android-3.1.html#launchcontrols

So if you want to start "stopped" application via Intent - you should add FLAG_INCLUDE_STOPPED_PACKAGES flag to Intent.

But problem is that i can't add FLAG_INCLUDE_STOPPED_PACKAGES flag to GCM Intent because GCM Intents (i mean "com.google.android.c2dm.intent.RECEIVE" and "com.google.android.c2dm.intent.REGISTRATION") are thrown by the OS.

So my question is: how can i handle push messages (on android 3.1) from GCM via broadcast reciever in situation when application (in which broadcastreceiver is registered) is closed (is in "stopped" state) ?

解决方案

how can i handle push messages (on android 3.1) from GCM via broadcast reciever in situation when application (in which broadcastreceiver is registered) is closed (is in "stopped" state) ?

You can't. If the user force-stops your app, nothing of your app will run again (on Android 3.1+) unless invoked manually, such as the user launching one of your activities. Your objective is to give the user no reason to force-stop your app.

这篇关于禁止广播接收器:在Android 3.1 GCM推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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