如何在android中制作一个聊天应用程序?

发布于 2024-10-09 01:46:05 字数 1435 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

一个人练习一个人 2024-10-16 01:46:05

要向 Android 应用程序添加聊天功能,有多种选择。我将按照所需的开发专业知识的数量(从最少到最多)列出选项。

使用实时后端服务

有许多公司提供实时后端服务。这些服务将为您提供一个 SDK,允许您的应用程序访问其服务器。使用 SDK,您将能够在设备之间传输数据。

以下是最受欢迎的服务列表:

Firebase

Google 拥有的实时数据库它使用 WebSockets 和 MongoDB 作为核心技术堆栈。该服务允许您将数据保存在非 SQL 数据库中,然后注册以在数据更改时接收实时更新。他们还提供推送通知和文件存储服务。还有一个适用于 iOSAndroid

Firebase 有一个名为 GeoFire 的库,它允许您让应用程序了解位置。

Pusher / PubNub

我将它们组合在一起,因为它们非常相似。他们提供实时流媒体基础设施和技术。您可以在设备组之间建立通道并在它们之间传输数据。他们不提供任何对用户进行身份验证的方法,因此您需要一个应用程序服务器。

Quickblox

Quickblox 专门针对即时消息市场,他们在后端使用 XMPP 服务器。由于他们使用 XMPP,因此该服务内置了许多消息传递功能,例如隐私列表和键入指示器。他们提供了一个合理但基本的示例消息应用程序。

Layer

Layer 介于 Quickblox 和 PubNub / Pusher 之间。他们提供了一个针对即时消息传递的流媒体平台。他们有一些消息传递功能,例如基本阻止,但这不是像 Quickblox 那样的全面消息传递实现。他们有一个 UI 组件库,可用于帮助构建完整的应用程序 - Atlas。

如果您使用后端作为服务,您将始终需要自己构建聊天客户端。如果您选择 Firebase 等更通用的选项之一,您还必须构建自己的消息传递协议。

这些服务将节省您在实时服务器实施、服务器配置和扩展方面的时间。

XMPP

另一种选择是自己托管 XMPP 服务器。有许多开源 XMPP 服务器可用:

XMPP 服务器将为您提供大量开箱即用的消息传递功能。它们通常不包含任何位置感知,但这可以通过将服务器配置为在单独的服务器上托管用户数据库来解决 - 这将允许您添加额外的表来处理地理位置。另一种方法是,当用户的位置发生一定程度的变化时,使用状态更新相关设备。

要构建客户端,我建议使用 Smack。由于 XMPP 是一个开放标准,因此您的客户端应该能够与第三方 XMPP 服务器和客户端一起使用。

如果您不想自己构建客户端,有许多开源项目(大部分在复制左许可证下)可以作为起点。 Xabber 就是一个示例,但您可以通过搜索找到更多信息。或者,您可以使用商业开源项目。

自己构建服务器

最后的选择是自己构建消息传递服务器。这样做的好处是您可以添加所需的功能并保持相当简单。一个好的方法是使用 SymfonyWebSocket 用于实时后端和 Android WebSockets 对于客户端。使用这种方法,您可以非常灵活地实现地理位置功能。

To add chat to an Android application there are a number of options. I'll present the options ordered by the amount of development expertise that's required - from least to most.

Using a real-time backend service

There are a number of companies offering real-time backend services. These services would provide you with an SDK which allows your app to access their servers. Using the SDK you would be able to stream data between devices.

Here is a list of the most popular services:

Firebase

Google owned real-time database which uses WebSockets and MongoDB as it's core technology stack. The service allows you to save data in a no-SQL database and then register to receive real-time updates when that data changes. They also offer services for push notification and file storage. There is also a third party open source messaging framework available for iOS and Android.

Firebase have a library called GeoFire which allows you to make your apps location aware.

Pusher / PubNub

I've grouped these together because they are quite similar. They provide real-time streaming infrastructure and technology. You can establish channels between groups of devices and stream data between them. They don't provide any means to authenticate users so you would need an app server.

Quickblox

Quickblox is targeted specifically at the instant messaging market and they use an XMPP server on the backend. Since they use XMPP, this service has a lot of messaging features built in like privacy lists and typing indicators. They provide a reasonable but basic example messaging app.

Layer

Layer is half way between Quickblox and PubNub / Pusher. They offer a streaming platform which is targeted towards instant messaging. They have some messaging features like basic blocking but this isn't a full scale messaging implementation like Quickblox. They have a library of UI components that can be used to help build a complete app - Atlas.

If you use a backend as a service you will always have to build the chat client yourself. If you go with one of the more general purpose options like Firebase, you will also have to build your own messaging protocol.

These services will save you time when it comes to the real-time server implementation, server configuration and scaling.

XMPP

Another option is to host an XMPP server yourself. There are a number of open source XMPP servers available:

XMPP servers will provide you with a large amount of messaging functionality out of the box. They generally don't include any location awareness but this could be solved by configuring the server to host the user database on a separate server - that would allow you to add extra tables to handle the geolocation. An alternative would be to use presence to update relevant devices when a user's location changed by a certain amount.

To build the client I would recommend using Smack. Since XMPP is an open standard, your client should be able to work with third party XMPP servers and clients.

If you don't want to build the client yourself there are a number of open source projects (mostly under copy left licenses) which could act as a starting point. Xabber would be one example but you can find more by searching. Alternatively, you could use this a commercial open source project.

Building the server yourself

The final option is to build the messaging server yourself. This has the benefit that you could add the features you need and keep it reasonably simple. A good approach would be to use Symfony and the WebSocket Bundle for the real-time back end and Android WebSockets for the client. Using this approach you would have a lot of flexibility implementing the geo location functionality.

不知在何时 2024-10-16 01:46:05

我与我的团队正在开发名为 QuickBlox 的后端即服务平台。
我们有一个很好的示例,说明如何将地图/聊天功能集成到您的应用程序中:

简单的 Android 地图/聊天应用程序:https:// Quickblox.com/developers/Android_XMPP_Chat_Sample

I & my team, we are working on Backend as a Service platform called QuickBlox.
We have great example how to integrate Map/Chat features to your application:

Simple Android Map/Chat application: https://quickblox.com/developers/Android_XMPP_Chat_Sample

流星番茄 2024-10-16 01:46:05

我们一直与开发者社区密切合作,开发了 Applozic Chat SDK,只需 10 分钟即可完成集成。尝试一下:Applozic
带有开源 SDK 的示例代码可在 Github 中找到: https://github.com/AppLozic/Applozic- Android-SDK

We have been working very closely with the developer community and have developed Applozic Chat SDK which takes just 10 mins for integration. Give it a try: Applozic
Sample code with open source sdk is available in Github: https://github.com/AppLozic/Applozic-Android-SDK

上课铃就是安魂曲 2024-10-16 01:46:05

我不了解 GMap,但要实现聊天,您可以尝试以下链接
Xmpp

I dont know about the about GMaps but for implementing chat you can try following link
Xmpp

冰葑 2024-10-16 01:46:05

添加聊天功能,您可以使用 Firebase 或 XMPP。

为了选择正确的选项,您可能更喜欢这个
https://www.quora.com/Which-protocol-is-better-to-develop-a-chat-web-app-using-Firebase-XMPP-or-HTTP

或者

如果您有强大的后端技术的知识,继续你自己的。同时,市场上还有一种即时解决方案,有助于更轻松地集成附加功能。

Adding a chat functionality, you can use Firebase or XMPP.

For choosing the right option you may prefer this
https://www.quora.com/Which-protocol-is-better-to-develop-a-chat-web-app-using-Firebase-XMPP-or-HTTP

OR

If you have strong knowledge of backend technologies, go ahead with your own. And the same time, there is also an instant solution available in the market that helps to integrate the additional functionality more easily.

筱果果 2024-10-16 01:46:05

我们提供了一个名为 ChatCamp 的实时聊天 SDK 解决方案。借助 ChatCamp SDK,您将能够快速向 Android 应用程序添加聊天功能。以下是 Android 快速入门指南的链接 - https://docs.chatcamp.io/文档/android-chat-quickstart。此外,还可以根据距特定位置的距离对用户列表进行排序,或者您可以在 Google 地图顶部显示在线用户。

We provide a real time chat SDK solution called ChatCamp. You would be able to add chat functionality to your Android app quickly with the help of ChatCamp SDK. Here is the link to Android quick start guide - https://docs.chatcamp.io/docs/android-chat-quickstart. Also, it is possible to order the user list based on the distance from a particular location or you may show online users on top of Google Maps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文