Пример #1
0
  private void sendMessages() {

    JSONObject json = Message.generateRequest(this);

    if (json != null) {

      HttpPost httpPost = new HttpPost(BASE_URL + URL_MESSAGES + getDeviceId());

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

      nameValuePairs.add(new BasicNameValuePair("messages", json.toString()));
      nameValuePairs.add(new BasicNameValuePair("address_email", address_email));
      nameValuePairs.add(new BasicNameValuePair("start", String.valueOf(start)));
      nameValuePairs.add(new BasicNameValuePair("time", time));

      try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        NetTaskRequest request = new NetTaskRequest(ACTION_SEND_MESSAGES, httpPost);
        NetTask task = new NetTask();
        task.execute(request);
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }

    } else {

      Toast.makeText(this, R.string.no_messages, Toast.LENGTH_LONG).show();
    }
  }
Пример #2
0
 /**
  * Connect to service and check if we have record in DB
  *
  * @return - the device id which is held in DB. If no device id then return null.
  */
 private void getSavedDeviceId() {
   String uri = BASE_URL + URL_LOGIN + getDeviceId();
   HttpGet request = new HttpGet(uri);
   NetTaskRequest netRequest = new NetTaskRequest(ACTION_GET_SAVED_ID, request);
   NetTask task = new NetTask();
   task.execute(netRequest);
 }
Пример #3
0
  private void saveCredentials() {
    String uri = BASE_URL + URL_LOGIN + getDeviceId();
    HttpPost request = new HttpPost(uri);

    List<NameValuePair> pairs = new ArrayList<NameValuePair>();

    // Read real credentials here

    pairs.add(new BasicNameValuePair("email", "*****@*****.**"));
    pairs.add(new BasicNameValuePair("password", "123123123123"));

    try {
      request.setEntity(new UrlEncodedFormEntity(pairs));
      NetTaskRequest netRequest = new NetTaskRequest(ACTION_SAVE_CREDENTIALS, request);
      NetTask task = new NetTask();
      task.execute(netRequest);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
Пример #4
0
  private void updateCredentials(String start) {
    String url = BASE_URL + URL_LOGIN + getDeviceId();
    HttpPut request = new HttpPut(url);

    List<NameValuePair> pairs = new ArrayList<NameValuePair>();

    // Read real data here (NOT IMPLEMENTED BECAUSE INTENTION OF THIS IS TO
    // demonstrate that we can handle those kind of tasks
    // rather that create something real working

    pairs.add(new BasicNameValuePair("email", "*****@*****.**"));
    pairs.add(new BasicNameValuePair("password", "123123123123"));
    pairs.add(new BasicNameValuePair("time", "0000000000000"));
    pairs.add(new BasicNameValuePair("start", start));

    try {
      request.setEntity(new UrlEncodedFormEntity(pairs));
      NetTaskRequest netRequest = new NetTaskRequest(ACTION_UPDATE_CREDENTIALS, request);
      NetTask task = new NetTask();
      task.execute(netRequest);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }