实施机器人一对一和群聊 [英] Implementing one to one and group chat in android

查看:155
本文介绍了实施机器人一对一和群聊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序中,我要实现的聊天通讯。我想一对一聊天群聊

I am developing an Android app in which I have to implement chat messaging. I would like one to one chat or a group chat.

不过,我不知道如何下手。请帮我这个东西。任何帮助将AP preciated。

But I have no idea how to start. Please help me with this stuff. Any help will be appreciated.

推荐答案

一个简单的聊天机制,将有2个基本功能

A simple chat mechanism will have 2 basic functionalities

  1. 将消息发送到服务器(与有关收件人的信息)

  1. Send the message to server (with info about the recipient)

接收来自服务器的消息(指定我的用户名)

Receive the message from server (designated for my user name)

第一步很简单,我们可以创建一个Web服务将接受该消息有关收件人(S)的更多信息。我们可以使用任何服务器端语言来创建它。

First step is simple, we can create a web service which will accept the message with additional information about recipient(s). We can create it using any server side language.

步骤2,是从服务器上获取的信息可以通过使用2技术,从服务器中拉出消息(使用轮询),或者从服务器推的消息android手机

Step 2, that is fetching the message from server can be done using 2 techniques, Pull the message (using polling) from server, or Push the message from server to android phone

  1. 查询:在这方面,Android设备将保持几秒钟后访问服务器,以检查是否有可用的用户的消息。这又可以使用在客户端,这将使调用Web服务之后,说2-3秒一个简单的异步任务来实现。这是蛮好用的,如果我们打算只启用聊天时用户正在访问的应用程序(如Gmail或Facebook没有通知),这样我们就可以杀死轮询服务时,不使用(否则会吃资源)。

  1. Polling: In this, the android device will keep accessing server after a few seconds to check if there is a message available for user. This again can be implemented using a simple async task at the client side which will keep calling a web service after say 2-3 seconds. This is fine to use if we are planning to enable chatting only when user is accessing the app (no notifications like gmail or facebook), so that we can kill the polling service when not in use (otherwise it will eat up resources).

推送通知:一个更好的选择是使用推送通知。 Android的谷歌提供云消息或GCM(http://developer.android.com/google/gcm/index.html),这将有助于轻松实现从推送服务器。否则,你可以尝试像urbanairship或pushwoosh第三方API根据您的要求。推送通知将有助于获得即使他不使用应用程序消息的用户。

Push notifications: a better option is to use push notifications. Android provide Google cloud messaging or GCM (http://developer.android.com/google/gcm/index.html) which will help achieve push from server easily. Otherwise you can try a third party API like urbanairship or pushwoosh depending on your requirement. Push notifications will help the user to receive messages even when he is not using the app.

所以,简单地说,一个web服务接收邮件和推送通知机制,应当有足够的机器人来实现聊天服务。

So in nutshell, a webservice to receive the messages and a push notification mechanism should be sufficient to implement a chat service in android.

有关UrbanAirship点点

Little bit about UrbanAirship

我用UA在我的项目之一的推送通知,因为我需要同时支持iOS和Android。如果你只是想支持Android GCM也可能是一个不错的选择。

I used UA in one of my projects for push notifications as I needed to support both iOS and Android. If you just want to support Android GCM might also be a good option.

现在回到UA,检查此样品code和用法:<一href="https://docs.urbanairship.com/display/DOCS/Home">https://docs.urbanairship.com/display/DOCS/Home

Coming back to UA, check this for sample code and usage: https://docs.urbanairship.com/display/DOCS/Home

它的工作方式很简单,当有人安装的应用程序,并连接到互联网,应用程序将自己注册为UA服务。独特的code指定为每个已安装的应用程序(这是时候,你可以捕获用户名和独特的code和在你的数据库存储在某个地方)。接下来UA提供了使用它你可以把一个消息给指定的收件人,用c $ CS它们可与UA独特的$的API。这些消息可以由机器人程序被接收并用作每要求。即使应用程序没有运行,我们可以证明,当我们收到一封电子邮件,或者仅仅是想通知的消息

The way it works is simple, when someone installs the app and is connected to internet, app registers itself to the UA service. A unique code is specified for each installed app (this is the time when you can capture the user name and unique code and store somewhere in your DB). Next UA provides an API using which you can push a message to designated recipient(s), using the unique codes which are available with UA. These messages can be received by android app and used as per the requirement. Even if the app is not running we can show a notification just like when we receive an email or a message

这篇关于实施机器人一对一和群聊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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