示例#1
0
  @Override
  protected String doInBackground(Void... params) {
    String responseString = null;

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(ResultListener.URL);
    try {
      AndroidMultiPartEntity entity =
          new AndroidMultiPartEntity(
              new AndroidMultiPartEntity.ProgressListener() {
                @Override
                public void transferred(long num) {
                  publishProgress((int) ((num / (float) totalSize) * 100));
                }
              });

      File sourceFile = new File(mImageUri);
      entity.addPart("image", new FileBody(sourceFile));
      entity.addPart("action", new StringBody("uploadFile"));

      totalSize = entity.getContentLength();
      httppost.setEntity(entity);

      HttpResponse response = httpclient.execute(httppost);
      HttpEntity r_entity = response.getEntity();

      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) {
        responseString = EntityUtils.toString(r_entity);
      } else {
        responseString = "Error occurred! Http Status Code: " + statusCode;
      }
    } catch (ClientProtocolException e) {
      responseString = e.toString();
    } catch (IOException e) {
      responseString = e.toString();
    }

    return responseString;
  }
示例#2
0
  public String InvokeGetFeed() {
    String responseString = null;

    HttpPost httppost = new HttpPost(Config.url_addSession);

    HttpClient httpclient = new DefaultHttpClient();

    try {
      AndroidMultiPartEntity entity =
          new AndroidMultiPartEntity(
              new AndroidMultiPartEntity.ProgressListener() {

                @Override
                public void transferred(long num) {}
              });

      // Adding file data to http body
      entity.addPart("Building_ID", new StringBody(session.getBuildingID()));
      entity.addPart("Point", new StringBody(session.getPoint()));
      entity.addPart("Floor", new StringBody(session.getFloor()));
      entity.addPart("Description", new StringBody(session.getDescription()));
      entity.addPart("Location", new StringBody(session.getLocation()));
      entity.addPart("Loc_Specification", new StringBody(session.getLoc_Specification()));
      entity.addPart("AWN_Status", new StringBody(session.getStatus_AWN()));
      entity.addPart("DTAC_Status", new StringBody(session.getStatus_DTAC()));
      entity.addPart("TRUEH_Status", new StringBody(session.getStatus_TRUEH()));
      entity.addPart("3BB_Status", new StringBody(session.getStatus_3BB()));
      entity.addPart("Remark", new StringBody(session.getRemark()));
      entity.addPart("Create_Date", new StringBody(session.getCreateDate().toString()));
      // entity.addPart("Confirm_Status",new StringBody(session.getConfirmStatus()));
      // entity.addPart("Confirm_Datetime",new StringBody(session.getConfirmDate().toString()));
      entity.addPart("User", new StringBody(session.getUser()));

      httppost.setEntity(entity);

      // Making server call
      HttpResponse response = httpclient.execute(httppost);
      HttpEntity r_entity = response.getEntity();

      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) {
        // Server response
        responseString = EntityUtils.toString(r_entity);
      } else {
        responseString = "Error occurred! Http Status Code: " + statusCode;
      }

    } catch (ClientProtocolException e) {
      responseString = e.toString();
    } catch (IOException e) {
      responseString = e.toString();
    }

    return responseString;
  }
    @SuppressWarnings("unused")
    @Override
    protected String doInBackground(Void... unsued) {

      SystemClock.sleep(2000);

      try {
        AndroidMultiPartEntity entityl =
            new AndroidMultiPartEntity(
                new AndroidMultiPartEntity.ProgressListener() {

                  @Override
                  public void transferred(long num) {
                    // publishProgress((int) ((num / (float) totalSize) * 100));
                  }
                });

        /*
        File sourceFile = new File(fileuri);


        // Adding file data to http body
        entity.addPart("videofile", new FileBody(sourceFile));*/
        String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();

        try {
          entityl.addPart("basepath", new StringBody(base));
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
        try {
          entityl.addPart("localfilepath", new StringBody(fileuri));
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
        try {
          entityl.addPart("name", new StringBody(deviceId));
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }

        // FileBody bin = new FileBody(new File("C:/ABC.txt"));

        try {
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost =
              new
              // Here you need to put your server file address
              HttpPost("http://torqkd.com/user/ajs/uploadvideoupdatelocation");
          // httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
          httppost.setEntity(entityl);
          HttpResponse response = httpclient.execute(httppost);
          // HttpEntity entity = response.getEntity();
          // is = entity.getContent();

          // Context context = videoActivity.this;
          // Intent cameraintent = new Intent(context, MainActivity.class);

          // Launch default browser
          // context.startActivity(cameraintent);
          Log.v("log_tag", "In the try Loop");
        } catch (Exception e) {
          Log.v("log_tag", "Error in http connection " + e.toString());
        }

      } catch (Exception e) {
        Log.v("log_tag", "Error in http connection " + e.toString());
      }

      return "Success";
      // (null);
    }