简体   繁体   English

通过从数据库中获取Google云消息传递

[英]Google cloud messaging by fetching from database

I'm working on getting news from server into the android application. 我正在努力将新闻从服务器发送到android应用程序中。 Now I'm thinking of getting push notification using google cloud messaging. 现在,我正在考虑使用Google云消息传递获得推送通知。 What I'm trying in my application is 我在应用程序中尝试的是

  1. Check regularly in server if there are any new data added to database. 定期检查服务器中是否有任何新数据添加到数据库。
  2. if yes then make a push notification. 如果是,则发出推送通知。

I'm not seeing any tutorial which does this thing. 我没有看到任何执行此操作的教程。 I only found android code. 我只找到了android代码。 Please help me on this. 请帮我。 I'm newbie to this concept. 我是这个概念的新手。

Thanks. 谢谢。

You have to options for this: 您必须为此选择:

1.. To contact your server from the app periodically and check if there are any new notifications. 1 ..通过应用程序定期与您的服务器联系,并检查是否有任何新通知。 If so you get the data and show it to the user. 如果是这样,您将获得数据并将其显示给用户。

-You can do this by scheduling an alarm, maybe once a day, that starts a service that does the server checking and notifying the user. -您可以通过安排警报(可能每天一次)来启动服务器,该服务可以执行服务器检查并通知用户的操作。 (this can be an ok solution if you know that new notifications will appear at fixed time intervals, i used it for an app that has show weekly news each Friday at noon) (如果您知道新的通知将以固定的时间间隔出现,那么这可能是一个好的解决方案,我将其用于在每个星期五中午显示每周新闻的应用程序)

2.. Google Cloud Messaging for Android 2 .. Android的Google Cloud Messaging

Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. Google Cloud Messaging for Android(GCM)是一项服务,可让您将服务器中的数据发送到用户使用Android的设备,也可以从同一连接的设备接收消息。 The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM服务处理消息排队和传递到目标设备上运行的目标Android应用程序的所有方面。 GCM is completely free no matter how big your messaging needs are, and there are no quotas. 无论您的消息传递需求有多大,GCM都是完全免费的,而且没有配额。

http://developer.android.com/google/gcm/index.html http://developer.android.com/google/gcm/index.html

I would recommend this if you want to be able to send notifications to users at any given time. 如果您希望能够在任何给定时间向用户发送通知,我建议您这样做。

You have nice tutorials on developer.android, its safe and reliable and you will have complete control over the process. 您可以在developer.android上找到不错的教程,它安全可靠,并且可以完全控制该过程。

I am currently working on implementing option 2, so i can update my experience on it once its done. 我目前正在实施选项2,因此一旦完成,我就可以更新自己的经验。

and here is an implementation tutorial on this one: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html 这是此实施指南: http : //www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html

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

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