论坛首页 移动开发技术论坛

Android 服务端消息推送 --求大神帮助

浏览 2744 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-01-08  
错误信息如下:



代码:
private boolean pushXmpp(JSONObject obj) throws Exception {
boolean result = true;
log.info("pushXmpp start");
try {
connect();
if (this.mConnected) {
String title = obj.getString("title");
int pushtype = obj.getInt("pushtype");
String paramid = obj.getString("paramid");
String paramid2 = obj.getString("paramid2");
String deviceid = obj.getString("deviceid");

// String to = deviceid + "@" + PropertiesUtils.XMPP_SERVICE_NAME;
Message msg = new Message();
obj.remove("deviceid");

// msg.setFrom(PropertiesUtils.USER_NAME + "@" + PropertiesUtils.XMPP_SERVICE_NAME);
// msg.setTo(to);
msg.setFrom(PropertiesUtils.XMPP_SERVICE_NAME);
msg.setTo(deviceid);
JSONObject messages = new JSONObject();
messages.put("title", title);
messages.put("pushtype",pushtype);
messages.put("paramid", paramid);
messages.put("paramid2", paramid2);
msg.setBody(messages.toString());
this.mConn.sendPacket(msg);


Thread.sleep(2000);
//log.info("pushXmpp sendTo:"+to +" success");
this.mConn.disconnect();
log.info("pushXmpp disconnect");
} else {
//throw new Exception("failed to connect Xmpp Server");
result = false;
}
} catch (Exception e) {
result = false;
//如果推送出现错误,跳过这个推送,保存日记记录
StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
    log.info(sw.toString());

//throw new JSONException(e.getMessage());
} finally {
this.mConn = null;
log.info("connect end");
}

return result;
}
  • 大小: 228.7 KB
   发表时间:2013-01-15  
XMPP协议复杂了, MQTT最合适
0 请登录后投票
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics