0
Ich bin Post Json Objektdaten mit Volley-Bibliotheken in meiner App, aber ich möchte die Antwort von dieser Anfrage und Update UI nach Antwort und zeigen auch progressdialog während Hintergrundprozess.how Kann ich das bitte sagen?Wie bekomme ich Antwort von Json mit Volley in Android
hier mein Code: -
public void postData() {
try {
getText();// get Input Text by the user
String json;// storing json object
JSONObject jsonObject = new JSONObject();
jsonObject.put("agentCode", s_szMobileNumber);
jsonObject.put("pin", s_szOldPassword);
jsonObject.put("newpin", s_szNewPassword);
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
System.out.println("Server Request:-" + json);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, CServerAPI.s_szChangePassUrl, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjectRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
public void getText() {// getting text from editText.....
s_szMobileNumber = m_MobileEditText.getText().toString().trim();// get mobile number from edit text
s_szNewPassword = m_NewPassEditText.getText().toString().trim();// get new pasword from edit Text
}
public void getResponse() throws JSONException {// method regarding condition.................
if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Transaction Successful")) {
s_szResponseNewPassword = m_oResponseobject.getString("newpin");// getting new password response from server....
CSnackBar.getInstance().showSnackBarSuccess(findViewById(R.id.mainLayout), "Password Changed Successfully", getApplicationContext());
upDatePassword();// updating password in shared preference.......
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent login = new Intent(getApplicationContext(), CLoginScreen.class);
startActivity(login);
}
}, 3500);
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Subscriber/Agent Not Found")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "User not found", getApplicationContext());
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("New Pin Can Not Be Empty")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "Enter valid password", getApplicationContext());
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Pin Can Not Be Empty")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "Old pin not found", getApplicationContext());
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Agentcode Can Not Be Empty")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "Enter valid mobile number", getApplicationContext());
}
}
public void upDatePassword() {// Update old password from new password in shared preference ......
m_Preferences = getApplicationContext().getSharedPreferences("LoginData", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = m_Preferences.edit();
editor.putString("pin", s_szResponseNewPassword);
editor.apply();
}
aber wie Bedingung zu machen, wie erwähnt – Nitin