【发布时间】:2014-10-21 15:30:55
【问题描述】:
我已经在 android 上完成了我的 IM 应用程序的开发(使用 xmpp 和 GCM),并且我正在使用 gcm 来进行 UpPayload 和 DownPayloads.. 并通知用户他的合作伙伴在线/离线我发送我的 xmpp 服务器“理解”的消息 告诉状态。
protected void onStart() {
super.onStart();
if(!isOnlineSent)
{SendOnlineStatus("Online");
isOnlineSent=true;}
.
.
.
.}
SendOnlineStatus 看起来像:
Intent OnlineMsg = new Intent();
OnlineMsg.putExtra("action", "com.Esmaeel.sodfarim.sodfa01.MESSAGE");
String nowtime = String.valueOf(EsTools.getCurrentTime());
OnlineMsg.putExtra(ConstantsGCM.TYPECLM, ConstantsGCM.ONST);
OnlineMsg.putExtra(ConstantsGCM.STATUS_on_of, Status);
OnlineMsg.putExtra(ConstantsGCM.TO_CLM, "-01");
OnlineMsg.putExtra(ConstantsGCM.FROMCLM, UUID);
OnlineMsg.putExtra(ConstantsGCM.MESSAGE_ID_CLM, regid + nowtime);
OnlineMsg.putExtra(ConstantsGCM.NAME_CLM, "Name");
final Bundle bndl = OnlineMsg.getExtras();
new AsyncTask() {
@Override
protected String doInBackground(Object[] objects) {
if (ggcm == null) {
ggcm = GoogleCloudMessaging.getInstance(context);
}
try {
ggcm.send(PRO_ID + ConstantsGCM.GCM_SERVER, bndl.getString(ConstantsGCM.MESSAGE_ID_CLM), bndl); //// GCM_SERVER="gcm.googleapis.com"
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
}.execute(null, null, null);
服务器检查值
payload.get(ConstantsGCM.TYPECLM); 如果类型 ONST 服务器读取值 payload.get(ConstantsGCM.STATUS_on_of); payload.get(ConstantsGCM.STATUS_on_of) 的有效值;是“在线”或“离线”。
然后服务器更新用户状态并将新状态发送给用户的所有朋友。
与打字状态相同,但最后一步我只发送到活动聊天的另一端。 但是我遇到了诸如“用户在离线时出现在线,有时在他不在时出现打字”之类的问题。 有什么帮助或更有效的想法吗?
【问题讨论】:
标签: android xmpp google-cloud-messaging