WebService JSON Parameter Example
class UserOtpRequest extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
pd = new ProgressDialog(ActivityOtp.this,"Validating OTP..");
pd.setCanceledOnTouchOutside(false);
pd.setCancelable(false);
pd.show();
}
@Override
protected String doInBackground(String... params) {
String result = "";
try {
JSONObject paramter = new JSONObject();
paramter.put("email", preference.getString("EmailID", ""));
paramter.put("otp", EditTextOtp.getText().toString().trim());
paramter.put("DeviceToken", preference.getString("GCMId", ""));
paramter.put("DeviceType", "Android");
result = HttpRequest.execute(Constants.UrlOtp
+ Constants.ValidateOtp, paramter);
} catch (Exception e) {
}
return result;
}
@Override
protected void onPostExecute(String result) {
String Status = "", Message = "";
if (pd != null && pd.isShowing()) {
pd.dismiss();
}
try {
if (result != null) {
JSONObject main_object = new JSONObject(result);
Status = main_object.getString("status");
Message = main_object.getString("message");
if (Status.contentEquals("true")) {
JSONObject data_object = main_object
.getJSONObject("data");
int id = data_object.getInt("ID");
String Emailid = data_object.getString("Email");
String Sex = data_object.getString("Sex");
String Country = data_object.getString("Country");
String Compnay = data_object.getString("Company");
String WorkTitle = data_object.getString("WorkTitle");
String Bio = data_object.getString("Bio");
String Chapter = data_object.getString("Chapter");
String Membertype = data_object.getString("Membertype");
String Name = data_object.getString("Name");
String PicURL = data_object.getString("PicURL");
String Active = data_object.getString("Active");
String Otp = data_object.getString("Otp");
}
}
} catch (Exception e) {
final Dialog dialog = new Dialog(ActivityOtp.this, "Error", "Not able to connect to the server, please try later");
dialog.setOnAcceptButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
dialog.dismiss();
}
});
dialog.show();
}
}
}