如何在后台继续在Android上听推送通知 [英] How to keep Listening for Push Notifications on Android in the background
问题描述
我正在研究Android中的推送通知。现在问题是,我想在应用程序启动后立即在后台运行我的推送通知,因为我不知道服务器何时将数据推送到设备。
主要要求是我们的企业应用程序有超过10项活动,并且基于收到的通知,我必须将相关活动放在前台,以便用户可以对此进行预处理操作或在背景,无论活动在前台。
有人可以建议我如何实现这种类型的需求。我需要在服务中做到这一点。
谢谢
Android设备上的Android应用程序无需运行即可接收消息。当消息到达时,系统会通过Intent广播唤醒Android应用程序,只要该应用程序使用正确的广播接收器和权限进行设置即可。
此;
http: //developer.android.com/guide/google/gcm/gcm.html
从gcm服务器收到消息时
onMessage(Context context,Intent intent):GCMIntentService的方法会被触发,
所以你在那里写你的代码
以这里的示例为例
https://github.com/ketanpatel25/GCM-Demo/tree/master/gcm
I am working on Push Notifications in Android. Now the issue is that I want to keep running my Push Notifications on the back ground as soon as the app start because I have no idea when the server will push the data to the devices.
The main requirement is that our corporate app is having more than 10 activities and based on the notification received, I have to bring the related activity on the foreground so that user can preform action on that or do some silent action in the background regardless the activity is in foreground.
Can somebody suggest how can I implement this type of requirement. Do I need to do it in a Service.
Thanks
An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
take look at this;
http://developer.android.com/guide/google/gcm/gcm.html
when message received from gcm server
onMessage(Context context, Intent intent): method of GCMIntentService gets fire,
so you write your code there
take sample example from here
https://github.com/ketanpatel25/GCM-Demo/tree/master/gcm
这篇关于如何在后台继续在Android上听推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!