private void download(String url) {
    try {
      mFile =
          FileUtil.getDestinationInExternalPublicDir(
              getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));

      PersistentCookieStore cookieStore =
          new PersistentCookieStore(AttachmentsDownloadDetailActivity.this);
      String cookieString = "";
      for (Cookie cookie : cookieStore.getCookies()) {
        cookieString += cookie.getName() + "=" + cookie.getValue() + ";";
      }

      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
      request.addRequestHeader("Cookie", cookieString);
      request.setDestinationInExternalPublicDir(
          getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));
      request.setTitle(mFileObject.getName());
      // request.setDescription(mFileObject.name);
      // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
      request.setVisibleInDownloadsUi(false);
      // request.allowScanningByMediaScanner();
      // request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
      // request.setShowRunningNotification(false);

      downloadId = downloadManager.enqueue(request);
      downloadListEditor.putLong(mFileObject.file_id, downloadId);
      downloadListEditor.commit();
    } catch (Exception e) {
      Toast.makeText(this, R.string.no_system_download_service, Toast.LENGTH_LONG).show();
    }
  }
  public void broadcastLocationFound(Location location) {

    String deviceId =
        Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);

    params = new RequestParams();
    params.put("UID", deviceId);
    params.put("LAT", Double.toString(location.getLatitude()));
    params.put("LON", Double.toString(location.getLongitude()));
    params.put("ACU", Double.toString(location.getAccuracy()));
    params.put("SPD", Double.toString(location.getSpeed()));

    PersistentCookieStore CookieStore = new PersistentCookieStore(LocationService.this);
    CookieStore.clear();
    AsyncHttpClient sendLocation = new AsyncHttpClient(false, 80, 443);
    sendLocation.setCookieStore(CookieStore);
    sendLocation.setTimeout(60000);
    sendLocation.post(
        url,
        params,
        new JsonHttpResponseHandler() {

          @Override
          public void onSuccess(
              int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            Log.i(TAG, response.toString());
          }

          @Override
          public void onSuccess(
              int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONArray response) {
            super.onSuccess(statusCode, headers, response);
            Log.i(TAG, response.toString());
          }

          @Override
          public void onSuccess(
              int statusCode,
              cz.msebera.android.httpclient.Header[] headers,
              String responseString) {
            super.onSuccess(statusCode, headers, responseString);
            Log.i(TAG, responseString);
          }

          @Override
          public void onFailure(
              int statusCode,
              cz.msebera.android.httpclient.Header[] headers,
              String responseString,
              Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
            Log.v(TAG, responseString, throwable);
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.i("Javier", "Finis2h");

    persistentCookieStore = new PersistentCookieStore(this);

    httpClient = new AsyncHttpClient();

    persistentCookieStore.clear();
    httpClient.setUserAgent(getUserAgent());
    httpClient.setCookieStore(persistentCookieStore);
    // httpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,
    // true);
    // httpClient.getHttpClient().getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
    // true);

    // PROXY SETTING HERE FOR FIDDLER
    // HttpHost proxy = new HttpHost("192.168.150.82", 8888);
    // httpClient.getHttpClient().getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
    // proxy);
    //
    // printCookies();

    getSupportActionBar().setTitle("metro");

    editText1 = (EditText) findViewById(R.id.editText1);
    editText2 = (EditText) findViewById(R.id.editText2);
    editText3 = (EditText) findViewById(R.id.editText4);
    accountDetails = (TextView) findViewById(R.id.textView1);
    securityCharacters = (TextView) findViewById(R.id.textView2);
  }
  /** 采用AsyncHttpClient的Post方式进行实现 */
  public void loginByAsyncHttpClientPost() {
    String url = "http://api.breadtrip.com/accounts/login/"; // 定义请求的地址
    // 创建请求参数的封装的对象
    RequestParams params = new RequestParams();
    params.put("username", "Sunsg"); // 设置请求的参数名和参数值
    params.put("password", "123456"); // 设置请求的参数名和参数
    client.setUserAgent(
        "BreadTrip/android/4.2.0/zh (android OS4.4.2) htc_m8tl Map/AutoNavi/v1.4.2 (HTC M8t,htc)");
    PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
    client.setCookieStore(myCookieStore);
    // 添加自己的cookiers
    BasicClientCookie newCookie = new BasicClientCookie("domain", ".breadtrip.com"); // name = value
    //        newCookie.setVersion(1);
    //        newCookie.setDomain(".breadtrip.com");
    //        newCookie.setPath("/");
    myCookieStore.addCookie(newCookie);
    // 执行post方法
    client.post(
        url,
        params,
        new AsyncHttpResponseHandler() {
          //
          /** 成功处理的方法 statusCode:响应的状态码; headers:相应的头信息 比如 响应的时间,响应的服务器 ; responseBody:响应内容的字节 */
          @Override
          public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            if (statusCode == 200) {
              for (int i = 0; i < headers.length; i++) {
                Logger.e("test", " header " + i + " = " + headers[i]);
              }

              Logger.e("test", "responsebody = " + new String(responseBody));
              syncCookies();
            }
          }
          /** 失败处理的方法 error:响应失败的错误信息封装到这个异常对象中 */
          @Override
          public void onFailure(
              int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            error.printStackTrace(); // 把错误信息打印出轨迹来
            Logger.e("test", "error = " + error.toString());
          }
        });
  }
  public void clickButton(View view) {

    // testLogin(MYACCOUNT_URL, true);

    // princeTest();

    persistentCookieStore.clear();
    testMetroBank();
    // testFirstMakePayment();
    // Applicant.getInstance().initializeData();
    // testApplyMrLendeR();
  }
  public void printCookies() {

    System.out.println("cookise " + persistentCookieStore.getCookies().size());
  }
  public List<cz.msebera.android.httpclient.cookie.Cookie> getCookies() {

    return myCookieStore.getCookies();
  }