@Override
    protected String doInBackground(String... params) {

      // Preparo la richiesta Post
      ArrayList<NameValuePair> postParams = new ArrayList<NameValuePair>();
      postParams.add(new BasicNameValuePair("date", UserData.getInstance().getDate()));
      postParams.add(
          new BasicNameValuePair(
              "cu",
              UserData.getInstance()
                  .getCU()
                  .substring(0, UserData.getInstance().getCU().length() - 2)));
      postParams.add(
          new BasicNameValuePair(
              "reprint",
              UserData.getInstance()
                  .getCU()
                  .substring(UserData.getInstance().getCU().length() - 1)));
      postParams.add(new BasicNameValuePair("search", params[0]));
      postParams.add(new BasicNameValuePair("imei", params[1]));

      String res = null;
      String response = null;
      try {

        Log.e("date", UserData.getInstance().getDate());
        Log.e(
            "cu",
            UserData.getInstance()
                .getCU()
                .substring(0, UserData.getInstance().getCU().length() - 2));
        Log.e(
            "reprint",
            UserData.getInstance().getCU().substring(UserData.getInstance().getCU().length() - 1));
        Log.e("search", params[0]);
        Log.e("imei", params[1]);

        response = CustomHttpClient.executeHttpPostString(URL_IDENT, postParams);
        res = response.toString();
        res = res.replaceAll("\\s+", "");

        Log.e("result", res);

        // Parso l'oggetto JSON che mi e' tornato
        JSONObject parsedObject = new JSONObject(res);
        String nome = parsedObject.getString("nome");
        String cognome = parsedObject.getString("cognome");
        String datanascita = parsedObject.getString("data");

        datumNome.put("title", nome);
        datumCognome.put("title", cognome);
        datumDataNascita.put("title", datanascita);

        Log.e("Found ", nome + " " + cognome + " " + datanascita);
      } catch (Exception e) {
        e.printStackTrace();
      }
      return res;
    }
Esempio n. 2
0
  public static String getByHttpClient(
      Context context, String strUrl, NameValuePair... nameValuePairs) throws Exception {
    String result = CustomHttpClient.getFromWebByHttpClient(context, strUrl, nameValuePairs);

    if (TextUtils.isEmpty(result)) {
      result = "";
    }

    return result;
  }
    @Override
    protected String doInBackground(String... params) {
      // TODO Auto-generated method stub
      String retstring = "";
      try {

        String fname = edtFname.getText().toString();
        String lname = edtLname.getText().toString();
        // String gender = edtGender.getText().toString();
        String email = edtEmail.getText().toString();
        // String age = edtAge.getText().toString();
        // String birth_info = edtBirthInfo.getText().toString();

        String day = null;
        String month = null;
        String year = null;
        String age = null;
        if (spDay.getVisibility() == View.VISIBLE) {
          day = spDay.getSelectedItem().toString();
          month = spMonth.getSelectedItemPosition() + "";
          year = spYear.getSelectedItem().toString();
        } else {
          age = edtAge.getText().toString();
        }

        SharedPreferences myPrefs =
            Profile_Edit.this.getSharedPreferences("remember", MODE_PRIVATE);
        String userid = myPrefs.getString("userid", null);
        ArrayList<NameValuePair> loginParam = new ArrayList<NameValuePair>();
        loginParam.add(new BasicNameValuePair("userid", userid));
        loginParam.add(new BasicNameValuePair("member_id", memid));
        loginParam.add(new BasicNameValuePair("fname", fname));
        loginParam.add(new BasicNameValuePair("lname", lname));
        loginParam.add(new BasicNameValuePair("gender", gender));
        loginParam.add(new BasicNameValuePair("email", email));
        loginParam.add(new BasicNameValuePair("age", age));
        loginParam.add(new BasicNameValuePair("birth_info", birth_info));
        loginParam.add(new BasicNameValuePair("birth_day", day));
        loginParam.add(new BasicNameValuePair("birth_month", month));
        loginParam.add(new BasicNameValuePair("birth_year", year));

        String response =
            CustomHttpClient.executeHttpPost(
                "http://ospinet.com/app_ws/android_app_fun/add_member", loginParam);

        retstring = response.toString();
      } catch (Exception io) {

      }
      return retstring;
    }
  public void getKeyClicked(View v) {

    SharedPreferences prefs = this.getSharedPreferences("SessionToken", MODE_PRIVATE);
    String session = prefs.getString("SessionToken", null);

    if (session == "null") {
      Toast noSession =
          Toast.makeText(
              MainActivity.this, "You do not have an active session!", Toast.LENGTH_LONG);
      noSession.show();
    } else {
      Toast gettingKey = Toast.makeText(MainActivity.this, "Getting the key...", Toast.LENGTH_LONG);

      ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
      postParameters.add(new BasicNameValuePair("getPoorSessionKey", serverKey));

      try {

        SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        String address = SP.getString("server_preference", "NA");

        String res = CustomHttpClient.executeHttpPost(address, postParameters);

        JSONObject jObject = new JSONObject(res);

        String response = (String) jObject.getString("JSESSIONID");

        System.out.println("SessionId: " + response);

        response = response.replaceAll("\\s+", "");

        Toast responseError = Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT);
        responseError.show();

        if (response.contains("Value ERROR") == true) {
          showKey.setText("Invalid Session Detected");
        } else {
          showKey.setText(response);
        }

      } catch (Exception e) {

        Toast responseError = Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG);
        responseError.show();

        showKey.setText(e.toString());
      }
    }
  }
    @Override
    protected String doInBackground(String... params) {
      // TODO Auto-generated method stub
      String retstring = "";
      try {

        String response =
            CustomHttpClient.executeHttpGet(
                "http://ospinet.com/app_ws/android_app_fun/get_members_details?member_id=" + memid);
        retstring = response.toString();

      } catch (Exception io) {

      }
      return retstring;
    }
    protected String doInBackground(String... params) {

      // TODO Auto-generated method stub
      String Friend_Request_count = "";
      try {
        ArrayList<NameValuePair> Friend_Request = new ArrayList<NameValuePair>();
        SharedPreferences myPrefs =
            Profile_Edit.this.getSharedPreferences("remember", Context.MODE_PRIVATE);
        String userId = myPrefs.getString("userid", null);
        Friend_Request.add(new BasicNameValuePair("user_id", userId));
        String response =
            CustomHttpClient.executeHttpPost(
                "http://ospinet.com/app_ws/android_app_fun/get_request_count", Friend_Request);
        Friend_Request_count = response.toString();

      } catch (Exception io) {

      }
      return Friend_Request_count;
    }
Esempio n. 7
0
 public static String postByHttpClient(
     Context context, String strUrl, NameValuePair... nameValuePairs) throws Exception {
   String result = CustomHttpClient.PostFromWebByHttpClient(context, strUrl, nameValuePairs);
   return result;
 }
    @Override
    protected String doInBackground(String... urls) {

      /* Code Below uses vidtomp3 remote api to convert video to MP3!
      - MP3 Download ;) */

      ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
      postParameters.add(
          new BasicNameValuePair("mediaurl", urls[0])); // Post Request mediaurl as parameter ;)

      String response_mp3 = null;

      String returnString = null;

      // execute request and get response ;)
      try {
        response_mp3 =
            CustomHttpClient.executeHttpPost(
                "http://www.vidtomp3.com/cc/conversioncloud.php", // vidtomp3 remove server api
                postParameters);

        Log.i("log_tag", "API Response: " + response_mp3);
        returnString =
            response_mp3.substring(
                response_mp3.indexOf("statusurl") + 12,
                response_mp3.length() - 4); // Returns the statusurl
        returnString = returnString.replace("\\", ""); // This removes backslashes from the url ;))
        Log.i("log_tag", "1st: " + returnString); // Logs statusurl returned by the api

        // Connects to statusurl..should get an XML document..anyway..I'm not parsing it ;)
        final DefaultHttpClient httpClient = new DefaultHttpClient();

        HttpGet httpGet = new HttpGet(returnString);

        while (!status.equals("finished") && !cancelled) { // Repeat until status is finished
          Log.i("log_tag", "Looping right now!");

          // Set timeout ;)
          final HttpParams httpParameters = httpClient.getParams();

          HttpConnectionParams.setConnectionTimeout(httpParameters, 5 * 1000);
          HttpConnectionParams.setSoTimeout(httpParameters, 5 * 1000);

          HttpResponse httpResponse = httpClient.execute(httpGet);
          HttpEntity httpEntity = httpResponse.getEntity();

          HashMap<String, String> data;
          if (httpEntity != null) {
            InputStream instream = httpEntity.getContent();
            Vidtomp3parser parser = new Vidtomp3parser();
            data = parser.parse(instream);
            status = data.get("status");
            if (status.equals("finished")) {
              videoid = data.get("videoid");
              title = data.get("file");
              mp3url = data.get("downloadurl");
              Log.i("log_tag", "2nd: " + mp3url); // This should return mp3 download url ;)
              downloadsize = data.get("filesize");
              if (mProgressDialog.isShowing()) { // If showing hide it
                mProgressDialog.dismiss(); // Dismiss ProgressDialog
              }
            } else {
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      spinner.setVisibility(View.GONE);
                      status_box.setText(getResources().getString(R.string.status_checking));
                      status_box.setTextColor(oldColors);
                      if (!mProgressDialog.isShowing()) { // If not showing we show it
                        mProgressDialog.setTitle(
                            getResources().getString(R.string.converting_title));
                        mProgressDialog.setMessage(
                            getResources().getString(R.string.converting_message));
                        mProgressDialog.setOnCancelListener(
                            new DialogInterface.OnCancelListener() {
                              @Override
                              public void onCancel(DialogInterface dialogInterface) {
                                cancelled = true;
                              }
                            });
                        mProgressDialog.show(); // Show ProgressDialog
                      }
                    }
                  });

              if (!cancelled) {
                Thread.sleep(1000); // Sleeps 1 sec on failed
              }
            }
          } else {
            break;
          }
        }

      } catch (ClientProtocolException e) {
        e.printStackTrace();
        return e.getMessage();
      } catch (IOException e) {
        e.printStackTrace();
        return e.getMessage();
      } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
      }

      return null; /* If it's not null something is srs wrong :( */
    }
Esempio n. 9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_order);
    report = (TextView) findViewById(R.id.showOrder);
    viewOrder = (TextView) findViewById(R.id.viewOrder);
    submitOrder = (Button) findViewById(R.id.submitOrder);
    String response = null;
    try {
      response =
          CustomHttpClient.executeHttpGet("http://joe.cs.unca.edu/~andryiiv/senior/report.php");
      String result = response.toString();
      if (result.equals("")) {
        report.setText("   Nothing to order  ");
      } else {
        try {
          returnString = "";
          JSONArray jArray = new JSONArray(result);
          for (int i = 0; i < jArray.length(); i++) {
            JSONObject json_data = jArray.getJSONObject(i);
            Log.i(
                "log_tag",
                "item: "
                    + json_data.getString("item")
                    + ", usedAmount: "
                    + json_data.getInt("usedAmount"));
            returnString +=
                "\n" + json_data.getString("item") + " -> " + json_data.getInt("usedAmount");
          }
        } catch (JSONException e) {
          Log.e("log_tag", "Error parsing data " + e.toString());
        }

        try {
          report.setText(returnString);
        } catch (Exception e) {
          Log.e("log_tag", "Error in Display!" + e.toString());
          ;
        }
        submitOrder.setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                String response = null;
                try {
                  response =
                      CustomHttpClient.executeHttpGet(
                          "http://joe.cs.unca.edu/~andryiiv/senior/order.php");
                  String result = response.toString();
                  viewOrder.setText(result);
                } catch (Exception e) {
                  Log.e("log_tag", "Error in http connection!!" + e.toString());
                }
              }
            });
      }
    } catch (Exception e) {
      Log.e("log_tag", "Error in http connection!!" + e.toString());
    }
  }