コード例 #1
0
ファイル: PushService.java プロジェクト: vmailru/test
  private void log(String message, Throwable e) {
    if (e != null) {
      Log.e(TAG, message, e);

    } else {
      Log.i(TAG, message);
    }
  }
コード例 #2
0
ファイル: ADController.java プロジェクト: vmailru/test
  private void doGetAdList(final AsyncTaskPayload payload) {
    AdverRequest request = (AdverRequest) payload.getData()[0];

    String jsonStr = JSONHelper.objToJson(request);

    HttpEntity entity = new ByteArrayEntity(jsonStr.getBytes());
    final String url = NetworkHelper.executeUrl(ServiceConstants.SERVICE_AD);
    Log.i(TAG + " url: =====>", url);
    Log.i(TAG + " jsonStr: =====>", jsonStr);
    NetworkHelper.asyncHttpClient.post(
        mContext,
        url,
        entity,
        "application/json; charset=utf-8",
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String content) {
            super.onSuccess(content);
            Log.i(TAG + " Response: =====>", content);
            BaseResponse response = null;
            response = NetworkHelper.doObject(url, content, AdverResponse.class);
            if (checkErrorResponse(payload, response, false)) {
              return;
            }
            if (response instanceof AdverResponse) {
              mAdList = ((AdverResponse) response).getData();
            }
            dismisDialog();
            mListener.onSuccess(payload.getTaskType());
          }

          @Override
          protected void handleFailureMessage(Throwable e, String responseBody) {
            err = responseBody;
            super.handleFailureMessage(e, responseBody);
          }

          @Override
          public void onFailure(Throwable error) {
            super.onFailure(error);
            if (StringUtils.isEmpty(err)) {
              onfailure(payload);
            } else {
              onfailures(payload, err);
            }
          }
        });
  }
コード例 #3
0
ファイル: PushService.java プロジェクト: vmailru/test
  private synchronized void start() {
    log("Starting service...");

    // Do nothing, if the service is already running.
    if (mStarted == true) {
      Log.w(TAG, "Attempt to start connection that is already active");
      return;
    }

    // Establish an MQTT connection
    connect();

    // Register a connectivity listener
    registerReceiver(
        mConnectivityChanged, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
  }
コード例 #4
0
ファイル: PushService.java プロジェクト: vmailru/test
  private synchronized void stop() {
    // Do nothing, if the service is not running.
    if (mStarted == false) {
      Log.w(TAG, "Attempt to stop connection not active.");
      return;
    }

    // Save stopped state in the preferences
    setStarted(false);

    // Remove the connectivity receiver
    unregisterReceiver(mConnectivityChanged);
    // Any existing reconnect timers should be removed, since we explicitly
    // stopping the service.
    cancelReconnect();

    // Destroy the MQTT connection if there is one
    if (mConnection != null) {
      mConnection.disconnect();
      mConnection = null;
    }
  }