public XmppManager getPushManager() {
    if (null != notificationService) {
      return notificationService.getPushManager();

    } else {
      // String username = Preferences.getUserName(Application.sharePref);
      // loginChatClient(username, username);
      Log.e(
          "notificationService====",
          "notificationServiceConnection=" + notificationServiceConnection);
      Log.e("notificationService====", "BeforeBindnotificationService=" + notificationService);

      this.bindService(
          NotificationService.getIntent(this),
          notificationServiceConnection,
          Context.BIND_AUTO_CREATE);
      loginXmppClient(
          Preferences.getUserName(Application.sharePref),
          Preferences.getUserName(Application.sharePref),
          notificationService.getPushManager());
      Log.e("notificationService====", "AffterBindnotificationService=" + notificationService);
      if (notificationService != null) {
        return notificationService.getPushManager();
      }
      return null;
    }
  }
  /** @return 退出应用操作 */
  public void exitApp() {
    try {
      log.debug("exit app and disconnect xmpp..");
      hasLogined = false;
      notificationService.disconnect(getChatManager());
    } catch (Exception e) {
      log.error("disconnect xmpp error!", e);
    }
    new AsyncTask<String, Integer, String>() {

      @Override
      protected String doInBackground(String... params) {
        MucManager.getInstanse(Application.this).offLine();
        return null;
      }
    }.execute();

    ThreadPlatformUtils.shutdownAllTask();
    IMModelManager.instance().clear();
    boolean outline = Preferences.getOutLine(Application.sharePref);
    if (!outline) {
      CubeApplication application = getCubeApplication();
      application.save(application);
    }
    LoginModel.instance().clear();
    activityManager.popAllActivity();
  }
  /** 初始化配置 */
  public void onCreate() {
    super.onCreate();
    initConfig();
    initStores();
    initServices();
    initHandlers();
    initPosts();

    httpClient = createHttpClient();
    // 初始化自定义Activity管理器
    activityManager = ActivityManager.getScreenManager();
    CrashReport crashReport = new CrashReport();
    crashReport.start(this);

    // 初始化图片管理器
    final int memClass =
        ((android.app.ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 8;
    AsyncImageManager.buildInstance(new LruImageCache(cacheSize));

    // 效能监控启动定时器代码

    mHandler.removeCallbacks(mUpdateTimeTask);
    mHandler.postDelayed(mUpdateTimeTask, 60000);
    int days = Preferences.getDayTime(sharePref);
    FileCopeTool.scanFilesAndDeleteAtpath(days);
  }
  @Override
  public void sessionIdCreated(final Long sessionId, MinaMobileClient minaMobileClient) {
    this.sessionId = sessionId;
    this.minaMobileClient = minaMobileClient;
    Preferences.saveSessionID(sessionId, Application.sharePref);

    //		ThreadPool.run(new Runnable() {
    //			@Override
    //			public void run() {
    //				HttpClient httpClient = new DefaultHttpClient();
    //				HttpPut httpPut = new HttpPut(URL.CHECKIN_URL);
    //
    //				try {
    //					httpPut.addHeader("Accept", "application/json");
    //					httpPut.addHeader("Content-Type", "application/json");
    //					DeviceCheckinVo checkinVo = new DeviceCheckinVo();
    //					checkinVo.setDeviceId(DeviceInfoUtil
    //							.getDeviceId(Application.this));
    //					// checkinVo.setAppId("51f787228314bd3f4de8f98e");
    //					checkinVo.setAppId(getCubeApplication().getAppKey());
    //					// checkinVo.setAlias(alias);
    //					checkinVo.setChannelId("mina");
    //					checkinVo.setDeviceName(android.os.Build.MODEL);
    //					// checkinVo.setGis("128,68");
    //					checkinVo.setOsName("android");
    //					checkinVo.setOsVersion(android.os.Build.VERSION.RELEASE);
    //					checkinVo.setPushToken(sessionId + "");
    //					checkinVo.setTags(new TagEntryVo[] { new TagEntryVo(
    //							"platform", "Android") });
    //
    //					httpPut.setEntity(new StringEntity(new Gson()
    //							.toJson(checkinVo), "utf-8"));
    //
    //					HttpResponse httpResponse = httpClient.execute(httpPut);
    //					int statusCode = httpResponse.getStatusLine()
    //							.getStatusCode();
    //					Log.d("MinaMobileClient", "签到 code == " + statusCode);
    //					if (statusCode == HttpStatus.SC_OK) {
    //						Log.d("MinaMobileClient", "Application 签到成功");
    //					}
    //				} catch (ClientProtocolException e) {
    //					Log.e("MessageContentHandler", "MessageContentHandler", e);
    //				} catch (IOException e) {
    //					Log.e("MessageContentHandler", "MessageContentHandler", e);
    //				}
    //			}
    //		});

    //		Log.i("ApplicationEx", "session authenticated " + sessionId);

  }
  /** 用户注销 */
  public void logOff() {
    try {
      log.debug("exit app and disconnect xmpp..");
      hasLogined = false;
      notificationService.disconnect(getChatManager());
    } catch (Exception e) {
      log.error("disconnect xmpp error!", e);
    }
    MucManager.getInstanse(this).offLine();
    showTopWindow(a);
    ThreadPlatformUtils.shutdownAllTask();
    Intent in = new Intent(BroadcastConstans.CANCEELDIOLOG);
    sendBroadcast(in);
    IMModelManager.instance().clear();

    boolean outline = Preferences.getOutLine(Application.sharePref);
    if (!outline) {
      CubeApplication application = getCubeApplication();
      application.save(application);
    }
    LoginModel.instance().clear();
    Intent i = null;
    if (PadUtils.isPad(this)) {
      i = new Intent();
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      i.setClass(this, FacadeActivity.class);
      i.putExtra("direction", 1);
      i.putExtra("type", "web");
      i.putExtra("isPad", true);
      i.putExtra("value", "file:///android_asset/www/pad/login.html");
    } else {

      // i = new Intent();
      // i.setClass(this, LoginActivity.class);
      // i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      i = new Intent();
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      i.setClass(this, FacadeActivity.class);
      i.putExtra("value", URL.PHONE_LOGIN_URL);
      i.putExtra("isPad", false);
    }
    activityManager.popAllActivity();
    // activityManager.popAllActivityExceptOne(FacadeActivity.class);
    startActivity(i);
  }
  public void saveModulerRecord(CubeModule cubeModule) {

    String userName = Preferences.getUserName(Application.sharePref);
    String name = this.getPackageName();
    String appName = name.substring(name.length() - 8, name.length());
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String loginTime = sdf.format(date);
    ViewModuleRecord v = new ViewModuleRecord();
    v.setAction("Module");
    v.setAppName(appName);
    v.setClassName("");
    v.setMethodName("");
    v.setModuleName(cubeModule.getName());
    v.setUserName(userName);
    v.setDatetimes(loginTime);
    StaticReference.userMf.createOrUpdate(v);
  }
  private void initConfig() {
    initWebUrls();
    EventBus.registerApp(this);
    /** 获取SharedPreferences对象 */
    sharePref = PreferenceManager.getDefaultSharedPreferences(this);
    Boolean b = Preferences.getFirsttime(Application.sharePref);
    // 判断是不是第一次安装应用,

    CubeApplication app = CubeApplication.getInstance(this);
    app.loadApplication();
    this.setCubeApplication(app);
    app.loadLocalModule();
    // 同步前先显示ui
    CubeModuleManager.getInstance().init(CubeApplication.getInstance(this));
    // 注册
    EventBus.getEventBus(TmpConstants.EVENTBUS_COMMON)
        .register(originalParser = new OriginalParser(this));
    EventBus.getEventBus(TmpConstants.EVENTBUS_COMMON).register(this);
    EventBus.getEventBus(TmpConstants.EVENTBUS_COMMON)
        .register(mdmSubsrcriber = new MdmSubsrcriber(this));
    // 开启定位
    new GeoManager(this.getApplicationContext());
  }
        @Override
        public void run() {

          final long start = handlerStartTime;
          long millis = System.currentTimeMillis() - start;
          int seconds = (int) (millis / 1000);
          int minutes = seconds / 60;
          seconds = seconds % 60;
          final String sessionKey = Preferences.getSESSION(Application.sharePref);
          final String appKey = getCubeApplication().getAppKey();

          System.out.println("----------------------线程开启了:" + minutes + "分," + seconds + "秒");
          try {
            final JSONArray ja = getJsonFromTable();
            System.out.println("上传JSON:" + ja.toString());
            if (!ja.toString().equals("[]")) {
              new Thread(
                      new Runnable() {

                        @Override
                        public void run() {
                          String posturl =
                              URL.BASE_WS
                                  + "csair-monitor/api/monitor/saveAll?appKey="
                                  + appKey
                                  + "&sessionKey="
                                  + sessionKey;
                          try {
                            System.out.println("开始上传");
                            HttpResponse response = postJson(posturl, ja);
                            String result = "";
                            int status = response.getStatusLine().getStatusCode();
                            Log.e("post请求返回状态为:", "" + status);
                            if (status == 200) {
                              result = EntityUtils.toString(response.getEntity());
                              int len = ja.length();
                              for (int i = 0; i < len; i++) {
                                try {
                                  delectedDataFromTable(
                                      new String[] {ja.getJSONObject(i).getString("datetimes")});
                                } catch (JSONException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                                }
                              }
                            }
                          } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                          } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                          }
                        }
                      })
                  .start();
            }
          } catch (Exception e) {
            System.out.println("-----------------线程异常终止了:" + minutes + "分," + seconds + "秒");
            return;
          }
          mHandler.postDelayed(this, 60000);
        }
  /** 更新用户标签 */
  public void refreshRegisrer() {

    String privileges = Preferences.getPrivileges(Application.sharePref);
    if (privileges == null || privileges.equals("")) {
      return;
    }
    String mytag = "";
    try {
      JSONArray privs = new JSONArray(privileges);
      for (int i = 0; i < privs.length(); i++) {
        String name = privs.getJSONObject(i).getString("name");
        if (name != null && !name.equals("")) {
          mytag += name + ",";
        }
      }
    } catch (JSONException e1) {
      e1.printStackTrace();
    }
    List<NameValuePair> values = new ArrayList<NameValuePair>();

    String names = getPackageName();
    values.add(new BasicNameValuePair("deviceId", DeviceInfoUtil.getDeviceId(this)));
    values.add(new BasicNameValuePair("appId", cubeApplication.getAppKey()));
    String username = Preferences.getUserName(Application.sharePref);
    String sex =
        Preferences.getSex(Application.sharePref) != null
            ? Preferences.getSex(Application.sharePref)
            : "";
    String phone = Preferences.getPhone(Application.sharePref);
    // 去掉了标签的userName,phone
    values.add(new BasicNameValuePair("alias", username));
    values.add(new BasicNameValuePair("tags", "{privileges=" + mytag + "sex=" + sex + "}"));

    HttpPut request = new HttpPut(URL.CHECKIN_URL + "/tags");
    request.setHeader(
        "Accept",
        "application/x-www-form-urlencoded, application/xml, text/html, text/*, image/*, */*");
    DefaultHttpClient client = new DefaultHttpClient();
    if (values != null && values.size() > 0) {
      try {
        UrlEncodedFormEntity entity;
        entity = new UrlEncodedFormEntity(values, "utf-8");
        request.setEntity(entity);
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
    }
    try {
      HttpResponse response = client.execute(request);
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode != 200) {

        return;
      }

    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }