Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. public void signup() throws JSONException {
  2. String firstname = edittext_fname.getText().toString();
  3. String lastname = editext_lname.getText().toString();
  4. String email = editext_email.getText().toString();
  5. String mobile = editext_mobile.getText().toString();
  6. String pass = editext_pass.getText().toString();
  7. String username = editext_user.getText().toString();
  8. String address = editext_add.getText().toString();
  9. String cityname = editText_city.getText().toString();
  10. String zipcode = editText_Zip.getText().toString();
  11. String city_id = editText_cityid.getText().toString();
  12. String birthdate = textView_birth.getText().toString();
  13. String statename = textView_state.getText().toString();
  14. String stateid = state_id;
  15.  
  16. JSONObject jsonObject = new JSONObject();
  17. jsonObject.put("first_name", firstname);
  18. jsonObject.put("last_name", lastname);
  19. jsonObject.put("birth_date", birthdate);
  20. jsonObject.put("email", email);
  21. jsonObject.put("user_name", username);
  22. jsonObject.put("password", pass);
  23. jsonObject.put("mobile_no", mobile);
  24. jsonObject.put("address", address);
  25. jsonObject.put("zip_code", zipcode);
  26. jsonObject.put("city_id", city_id);
  27. jsonObject.put("city", cityname);
  28. jsonObject.put("state_id", stateid);
  29. jsonObject.put("reference_name", "xxx");
  30. jsonObject.put("country_id", "223");
  31. jsonObject.put("refer_by", "others");
  32. jsonObject.put("user_role_type", "3");
  33.  
  34. if (jsonObject.length() > 0) {
  35. new sendJsonData().execute(String.valueOf(jsonObject));
  36. }
  37.  
  38.  
  39. }
  40.  
  41. private class sendJsonData extends AsyncTask<String, Void, String> {
  42. ProgressDialog progressDialog;
  43. String Jsonresponse = null;
  44.  
  45. @Override
  46. protected void onPreExecute() {
  47. super.onPreExecute();
  48. progressDialog = new ProgressDialog(FirstScreenActivity.this);
  49. progressDialog.setMessage("please wait");
  50. progressDialog.setCancelable(false);
  51. progressDialog.show();
  52. }
  53.  
  54. @Override
  55. protected String doInBackground(String... params) {
  56.  
  57. String Jsondata = params[0];
  58.  
  59. HttpURLConnection urlConnection = null;
  60. BufferedReader reader = null;
  61. try {
  62.  
  63. URL url = new URL(WsUtils.BASE_URL+WsUtils.SIGNUP);
  64. urlConnection = (HttpURLConnection) url.openConnection();
  65. urlConnection.setDoOutput(true);
  66. urlConnection.setRequestMethod("POST");
  67. urlConnection.setConnectTimeout(10000);
  68. urlConnection.setRequestProperty("Accept","application/json");
  69. urlConnection.setRequestProperty("Content-Type","application/json");
  70.  
  71. //Writer writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8"));
  72. //writer.write(Jsondata);
  73. // writer.close();
  74.  
  75. DataOutputStream printout = new DataOutputStream(urlConnection.getOutputStream ());
  76. printout.writeBytes("PostData=" + Jsondata);
  77. printout.writeBytes(Jsondata);
  78. Log.e("json", Jsondata);
  79.  
  80. // printout.flush ();
  81. // printout.close ();
  82.  
  83. DataInputStream in = new DataInputStream(urlConnection.getInputStream());
  84. Jsonresponse = convertStreamToString(in);
  85.  
  86.  
  87.  
  88.  
  89. return Jsonresponse;
  90.  
  91.  
  92. } catch (MalformedURLException e) {
  93. e.printStackTrace();
  94. } catch (IOException e) {
  95. e.printStackTrace();
  96. }
  97.  
  98. return null;
  99. }
  100.  
  101.  
  102. @Override
  103. protected void onPostExecute(String s) {
  104. super.onPostExecute(s);
  105. progressDialog.dismiss();
  106. Log.e("response", Jsonresponse);
  107.  
  108. }
  109.  
  110.  
  111. }
  112.  
  113. public String convertStreamToString(InputStream is) {
  114. BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  115. StringBuilder sb = new StringBuilder();
  116.  
  117. String line;
  118. try {
  119. while ((line = reader.readLine()) != null) {
  120. sb.append(line).append('n');
  121. }
  122. } catch (IOException e) {
  123. e.printStackTrace();
  124. } finally {
  125. try {
  126. is.close();
  127. } catch (IOException e) {
  128. e.printStackTrace();
  129. }
  130. }
  131. return sb.toString();
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement