Android:通过SERVER获取在线或离线状态 [英] Android :Get Online or Offline status through SERVER

查看:238
本文介绍了Android:通过SERVER获取在线或离线状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android 4.0.3(即ICS)版本创建一个应用程序,当客户端登录到该应用程序时它将连接到服务器.我正在尝试通过服务器&联机或脱机获取客户端的状态.在应用程序屏幕上看到的.我无法继续.谁能说我:

是否可以通过服务器获取用户状态?

1--如何进行第一步...?

2--我应如何从服务器获得客户端已连接的响应?查看其他客户端示例-当我们登录Skype时,状态显示带有绿色的单选按钮,以同样的方式我该如何获得它?

如果有人指导我,它将非常有帮助. 非常感谢.

解决方案

我假设您正在尝试开发聊天应用程序?

在这种情况下,请尝试使用XMPP库. XMPP被广泛用于聊天应用程序,包括Facebook聊天(我认为是Google聊天),并且有很多开源库可用.

否则,如果您只想将实时通知作为大图的一部分,请尝试使用推送通知. Google支持Android的云到设备消息传递(C2DM).它允许向特定设备发出推送通知,而无需处理持久连接,电池和CPU使用情况等.

C2DM方法可以归结为这一点.当客户端连接到您的服务器时,获取其朋友及其"C2DM ID"的列表,然后将C2DM推送到其设备.此推送已传递到您的应用,您可以通过触发通知来响应它,或更新UI .etc. (您的应用程序不一定必须运行.推送通知是通过特定的广播传递的,您的应用程序可以注册接收方以将其唤醒.)

请记住,每个设备,每个应用都有C2DM消息的配额,还有每个消息的有效负载的限制.因此,您不应该通过此方式发送大量文件.只是通知您的应用程序,因此它可以调用您的服务器并获取更新的列表,而无需轮询.

您可以在此处获取有关C2DM和代码示例的更多信息. https://developers.google.com/android/c2dm/

希望这会有所帮助.

I am creating a app in android 4.0.3 i.e ICS version, which connects to the server when client gets login into the app.I am trying to get status of an client when he gets online or offline through server & seen onto the app screen.I am unable to proceed. Can anyone say me:

Is it possible to get the status of an user through server?

1-- How to proceed for first step...?

2-- How should I get a response from the server that the client is connected & viewed to other client example - when we login into skype our status shows available with green radio button, In same way how can I get it.?

It ll be very help full, If anybody guide me. Many Thanks..

解决方案

I'm assuming you're trying to develop a chat app ?

If this is the case, try using an XMPP library. XMPP is widely used for chat apps, including Facebook chat (and Google talk I think) and there are plenty of open source libraries available.

Otherwise, if you only want real-time notifications as a part of a bigger picture, try using push notifications. Google supports Cloud to Device Messaging (C2DM) for android. It allows to have push notifications to a specific device without you having to deal with persistent connections, battery and CPU use .etc.

C2DM approach comes down to this. When a client connects to your server, get a list of his friends and their 'C2DM IDs' and fire a C2DM push to their devices. This push is delivered to your app, and you can respond to it by firing a notification, or update UI .etc. (Your app doesn't necessarily have to be running. Push notification is delivered via a specific broadcast, and your app can register a receiver for it to wake up.)

Keep in mind that there is a quota for C2DM messages per device, per app and also a limit for the payload per message. So you're not supposed to send massive files via this. Just a notification to your app, so it can call your server and get an updated list, instead of polling.

You can get more info on C2DM and code samples here. https://developers.google.com/android/c2dm/

Hope this helps.

这篇关于Android:通过SERVER获取在线或离线状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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