[英]How do I alert users of an Android app when new data is posted to a remote server?
I am developing an Android application for an already existing website. 我正在为一个已经存在的网站开发一个Android应用程序。 When ever a user enters some data into the website (like a forum post), all the other users should be alerted about that post.
每当用户在网站中输入一些数据(例如论坛帖子)时,所有其他用户都应收到有关该帖子的警报。 Is it possible?
可能吗?
I think this is possible with triggers. 我认为使用触发器可以做到这一点。 Am I correct?
我对么?
You can try 'Android Cloud to Device Messaging Framework' which can push messages to your android application. 您可以尝试使用“ Android云到设备消息传递框架”,该框架可以将消息推送到您的android应用程序。
http://code.google.com/android/c2dm/ http://code.google.com/android/c2dm/
What you search for is called "Server pushing". 您搜索的内容称为“服务器推送”。 Your "listeners/observers", these are the mobile phones, register to a subject (in this case the server) at initialization.
您的“听众/观察者”是移动电话,在初始化时注册到主题(在这种情况下为服务器)。 Then they are listening for new calls all the time (Thread).
然后他们一直在监听新的呼叫(线程)。 If the data on server will be refreshed, every observer gets a call.
如果将刷新服务器上的数据,则每个观察者都会接到一个电话。 If your server is running on Java, you could use "observer pattern" for this.
如果您的服务器在Java上运行,则可以为此使用“观察者模式”。 Maybe you could use UDP calls to notify your observers.
也许您可以使用UDP调用来通知您的观察者。 After your observers receive the call, they "refresh" their data via an usual HTTP call.
观察者收到呼叫后,他们将通过常规HTTP呼叫“刷新”其数据。 If you are running php with a database you could save the IPs of your observers into the database (when they register on the server) iterate over it, and send them an UDP call, after a form submit is executed.
如果您使用数据库运行php,则可以在执行表单提交后将观察者的IP保存到数据库中(当他们在服务器上注册时),并对其进行迭代,并向他们发送UDP调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.