/**
  * 判断OpenFire用户的状态 strUrl : url格式 - http://my.openfire.com:9090/plugins/presence
  * /status?jid=user1@SERVER_NAME&type=xml 返回值 : 0 - 用户不存在; 1 - 用户在线; 2 - 用户离线 说明 :必须要求 OpenFire加载
  * presence 插件,同时设置任何人都可以访问
  */
 public int IsUserOnLine(String user) {
   String url =
       "http://"
           + XmppConnection.getConnection().getHost()
           + ":9090/plugins/presence/status?"
           + "jid="
           + user
           + "\\40"
           + XmppConnection.getConnection().getServiceName()
           + "&type=xml";
   int shOnLineState = -1;
   try {
     URL oUrl = new URL(url);
     URLConnection oConn = oUrl.openConnection();
     if (oConn != null) {
       BufferedReader oIn = new BufferedReader(new InputStreamReader(oConn.getInputStream()));
       if (null != oIn) {
         String strFlag = oIn.readLine();
         oIn.close();
         System.out.println("strFlag" + strFlag);
         if (strFlag.indexOf("type=\"unavailable\"") >= 0) {
           shOnLineState = 2;
         }
         if (strFlag.indexOf("type=\"error\"") >= 0) {
           shOnLineState = 0;
         } else if (strFlag.indexOf("priority") >= 0 || strFlag.indexOf("id=\"") >= 0) {
           shOnLineState = 1;
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return shOnLineState;
 }
 private void exit() {
   // 当前用户下线
   if (XmppConnection.getConnection() != null) {
     XmppConnection.getConnection().disconnect();
   }
   // SingleChatListActivity.this.finish();// 退出本程序
   System.exit(0);
 }