Getting wrong response in volley - android

I am getting wrong response in volley while on the other hand postman getting correct response. Please help me where is the problem . Response i am getting from volley is "response= {"code":1020,"message":"Duplicate key not allowed","returnId":null}"
And in postman it is "{
"code": 1089,"message": "Activation Key sent in email, please activate your user/device","returnId": 438
}"
public void sendRegisterationReq("http://demo.innowi.com/v1/user/register",getJsonObject()) {
RequestQueue queue = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
url, dataObj,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
// Toast.makeText(context, "" + response.toString(), Toast.LENGTH_SHORT).show();
System.out.println("response= " + response.toString());
System.out.println(TAG + ":" + dataObj.toString());
try {
if (response.getString("code").equals("1020")){
Intent intent = new Intent(RegisterDeviceActivity.this,ActivateDeviceActivity.class);
startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
String message = null;
if (volleyError instanceof NetworkError) {
message = "Network error!";
Log.d(TAG,message);
} else if (volleyError instanceof ServerError) {
message = "Server error!!";
Log.d(TAG,message);
} else if (volleyError instanceof AuthFailureError) {
message = "Auth failure error!";
Log.d(TAG,message);
} else if (volleyError instanceof ParseError) {
message = "Parsing error!";
Log.d(TAG,message);
} else if (volleyError instanceof NoConnectionError) {
message = "No connection error!";
Log.d(TAG,message);
} else if (volleyError instanceof TimeoutError) {
message = "timeout error !";
Log.d(TAG,message);
}
/*Toast.makeText(context, "error", Toast.LENGTH_SHORT).show();
System.out.println(TAG + ":Error: " + volleyError.getMessage());
System.out.println(TAG + ":" + volleyError.toString());*/
System.out.println(TAG + ":" + dataObj.toString());
}
}) {
/**
* Passing some request headers
* */
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
jsonObjReq.setShouldCache(false);
jsonObjReq.setTag("myRequest");
// Adding request to request queue
queue.add(jsonObjReq);
}
public JSONObject getJsonObject(){
JSONObject object = new JSONObject();
try {
if (username!=null && password !=null) {
object.put("username", username.getText().toString());
object.put("password", password.getText().toString());
object.put("deviceMacAddress", "90:B6:86:0D:CE:4F");
}
else
{
Toast.makeText(this, "Email/password should not be empty", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return object;
}

you are the data which is already exist in your database so says duplicate key try different one or try to send all fields valid and different.

Related

Device ID is not going to the heasers

Im working on Registration using volley liabray.I want to send Device ID in header but it going null here is my code snippit.
Log.d("TAG", "Details:" + response);
String strMessage = response.optString("message");
String strDevice = response.optString("deviceID");
CryptoHandler cryptoHandler = new CryptoHandler();
String decryptMessage = cryptoHandler.decrypt(strMessage);
String decryptDevice = cryptoHandler.decrypt(strDevice);
Log.d("TAG","Decrypted Response:"+decryptMessage +decryptDevice);
// responseTV.setText("String Response : " + response.toString());
Intent i = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(i);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
// responseTV.setText(error.getMessage());
// Toast.makeText(RegisterActivity.this, "Error"+error, Toast.LENGTH_LONG).show();
if (error instanceof NetworkError) {
} else if (error instanceof ServerError) {
} else if (error instanceof AuthFailureError) {
} else if (error instanceof ParseError) {
} else if (error instanceof NoConnectionError) {
} else if (error instanceof TimeoutError) {
Toast.makeText(getApplicationContext(),
"Oops. Timeout error!",
Toast.LENGTH_LONG).show();
}
}
//This is for Headers If You Needed
}) {
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("DeviceId", ID);
return headers;
}
};
requestQueue.add(jsonObjectRequest);

Getting response code from volley error response

How do we get response code and message of an errenous response from client? Here error.toString() returns: com.android.volley.ServerError error.getMEssage(): null error.getCause(): null parseNetworkResponse: never ever enters that function. When I add getParams() method, it may return ClientError but response code etc still doesnt work!!!!!!! I am trying this for the last 24 hours. No answer on anywhere.
private void getStudentInfo(String number){
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
final String url = organizationRoot+"/identity/detailed/" +number ;
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
txtTagContent.setText(response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
txtTagContent.setText("ERROR " + error.toString() + error.getMessage() + error.getCause());
}
}){
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
return requestHeaders;
}
#Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
txtTagContent.setText("WORKED ");
return Response.success( "", HttpHeaderParser.parseCacheHeaders(response));
}
};
requestQueue.add(stringRequest);
}
Could you try:
int statusCode = error.networkResponse.statusCode;
Log.e(TAG, String.valueOf(statusCode);
Maybe you can try this
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
String message = null;
if (error instanceof NetworkError) {
message = "Cannot connect to Internet...Please check your connection!";
} else if (error instanceof ServerError) {
message = "The server could not be found. Please try again after some time!!";
} else if (error instanceof AuthFailureError) {
message = "Cannot connect to Internet...Please check your connection!";
} else if (error instanceof ParseError) {
message = "Parsing error! Please try again after some time!!";
} else if (error instanceof NoConnectionError) {
message = "Cannot connect to Internet...Please check your connection!";
} else if (error instanceof TimeoutError) {
message = "Connection TimeOut! Please check your internet connection.";
}
Toast.makeText(LoginActivity.this, message, Toast.LENGTH_SHORT).show();
}
}

how can send JSON?

I'm trying to send a JSON to web service using Google Cloud API but keep getting the error below;
ERROR == 415
"E/Volley: [293] BasicNetwork.performRequest: Unexpected response code 415 for http://172.17.1.169:8080/api/save"
Here the code:
mTextMod.setText(text);
JSONObject jsonParam = new JSONObject();
try {
jsonParam.put("text", text);
jsonParam.put("language", "gl-ES");
jsonParam.put("voice", "Vocalizer Expressive Carmela Harpo 22kHz");
jsonParam.put("rate", null);
jsonParam.put("volume", "90");
System.out.println("patata ->" + jsonParam.toString());
} catch (JSONException e) {
e.printStackTrace();
}
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Request.Method.GET,
url,
jsonParam,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Toast.makeText(MainActivity.this, response.toString(),
Toast.LENGTH_LONG).show();
System.out.println(response.toString());
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
System.out.println(error.toString());
NetworkResponse networkResponse = error.networkResponse;
}
if (networkResponse != null) {
Log.e("Volley", "Error. HTTP Status Code:" + networkResponse.statusCode);
}
if (error instanceof TimeoutError) {
Log.e("Volley", "TimeoutError");
} else if (error instanceof NoConnectionError) {
Log.e("Volley", "NoConnectionError");
} else if (error instanceof AuthFailureError) {
Log.e("Volley", "AuthFailureError");
} else if (error instanceof ServerError) {
Log.e("Volley", "ServerError");
} else if (error instanceof NetworkError) {
Log.e("Volley", "NetworkError");
} else if (error instanceof ParseError) {
Log.e("Volley", "ParseError");
}
}
});
queue.add(jsonObjectRequest);
/**
* Pass request headers
*/
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
/**
*like below
*/
JSONObject jsonParam = new JSONObject();
try {
jsonParam.put("text", text);
jsonParam.put("language", "gl-ES");
jsonParam.put("voice", "Vocalizer Expressive Carmela Harpo 22kHz");
jsonParam.put("rate", null);
jsonParam.put("volume", "90");
System.out.println("patata ->" + jsonParam.toString());
} catch (JSONException e) {
e.printStackTrace();
}
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, jsonParam, new Response.Listener<JSONObject>(){
#Override
public void onResponse(JSONObject response) {
Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_LONG).show();
System.out.println(response.toString());
}
}, new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
System.out.println(error.toString());
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null) {
Log.e("Volley", "Error. HTTP Status Code:" + networkResponse.statusCode);
}
if (error instanceof TimeoutError) {
Log.e("Volley", "TimeoutError");
} else if (error instanceof NoConnectionError) {
Log.e("Volley", "NoConnectionError");
} else if (error instanceof AuthFailureError) {
Log.e("Volley", "AuthFailureError");
} else if (error instanceof ServerError) {
Log.e("Volley", "ServerError");
} else if (error instanceof NetworkError) {
Log.e("Volley", "NetworkError");
} else if (error instanceof ParseError) {
Log.e("Volley", "ParseError");
}
}
})
{
/**
* Passing some request headers
*/
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
queue.add(jsonObjectRequest);

Android Volley ServerError GET-Method

I've developed a REST webservice and consume it by android client.
The webservice works fine but sometimes android volley got a com.android.volley.ServerError. If I check the url with postman everything works. This problem is just by some few users and I cannot reproduce the error.
Here is my Volley request:
public void requestURL(final RestCallback callback) {
Log.d("JSON", url);
JsonArrayRequest jsonObjectRequest = new JsonArrayRequest
(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
callback.onSuccess(response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("JSON", "onErrorResponse: " + url);
String errorText = null;
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
Log.d("Error", "Timeouterror");
errorText = context.getString(R.string.error_timeout);
} else if (error instanceof ServerError) {
Log.d("Error", "Servererror");
errorText = context.getString(R.string.error_server);
} else if (error instanceof NetworkError) {
Log.d("Error", "Servererror");
errorText = context.getString(R.string.error_network);
} else if (error instanceof ParseError) {
Log.d("Error", "Parseerror");
errorText = context.getString(R.string.error_parse);
}
Crashlytics.logException(new Throwable("Errornachricht: " + error.getMessage() + " Error: " + error.toString() + "\n URL: " + url + "\n Cause: " +error.getCause() + " Stacktrace: " + error.getStackTrace()));
callback.onError(errorText);
}
}) {
#Override
public Map<String, String> getHeaders() {
return Security.getAuth();
}
#Override
protected Map<String, String> getParams() throws AuthFailureError {
return super.getParams();
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
//sets time for retry connection
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy( 0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
jsonObjectRequest.setShouldCache(false);
//Adding request to the queue
requestQueue.add(jsonObjectRequest);
}
And the method getAuth which is called bei getHeaders:
public static Map<String, String> getAuth() {
String credentials = "username" + ":" + "password";
String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
HashMap<String, String> headers = new HashMap<>();
headers.put("Accept","application/json");
headers.put("Content-Type","application/json");
headers.put("Authorization", "Basic " + base64EncodedCredentials);
return headers;
}
Error log:
Has anybody an idea why I got this error?
I think some times API response is not a valid JsonArray, at that time it will throw a server error. API response is a "null" or a jsonObject like wise

How to dismiss Progress Dialog when Swipe to refresh is Refreshing in android?

I have an app in which inside onCreate its sending request to server and I have added a SwipeRefresh when I swipe down again, the request is sent to server.
Problem is that when I swipe down, a ProgressDialog is shown to me which I don't want. What I want is, if swipe is refreshing then don't show the ProgressDialog, otherwise show ProgressDialog.
Code:-
m_SwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
getWalletBalance();
}
});
/* Here in this method we send request to server for wallet balance */
private void getWalletBalance() {
CLoginSessionManagement s_oSessionManagement = new CLoginSessionManagement(getApplicationContext());// making object of Registartion session management
// retreive user data from shared preferencce........
HashMap<String, String> user = s_oSessionManagement.getLoginDetails();// getting String from Regisatrtion session
String m_szMobileNumber = user.get(CLoginSessionManagement.s_szKEY_MOBILE).trim();
String m_szEncryptedPassword = user.get(CLoginSessionManagement.s_szKEY_PASSWORD).trim();
try {
String json;
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.put("agentCode", m_szMobileNumber);// sending mobile no.(static right know becuse of ser side data on other is null
jsonObject.put("pin", m_szEncryptedPassword);// same here as said above
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
Log.i(TAG, "Server request:-" + json);
//here I am getting error
m_Dialog = DialogUtils.showProgressDialog(getApplicationContext(),"Fetching wallet details...");
final String s_szWalletURL = "http://metallica/getWalletBalanceInJSON";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, s_szWalletURL, jsonObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.e(TAG, "Server Response:-" + response);
if (m_SwipeRefresh.isRefreshing()){
m_SwipeRefresh.setRefreshing(false);
}else {
m_Dialog.dismiss();
}
try {
int nResultCodeFromServer = Integer.parseInt(response.getString("resultcode"));
if (nResultCodeFromServer == CStaticVar.m_kTRANSACTION_SUCCESS) {
s_szWalletBalance = response.getString("walletbalance").trim();// get wallet balance fro response
String trimwalletBalance = s_szWalletBalance.substring(0, s_szWalletBalance.indexOf("."));// trim waalet balance from response.
CWalletDataModel.getInstance().setS_szWalletBalance(trimwalletBalance);// set wallet balance
// showing wallet transaction in textView....
m_WalletText.setText(CWalletDataModel.getInstance().getS_szWalletBalance());
} else if (nResultCodeFromServer == CStaticVar.m_kCONNECTION_NOT_AVAILABLE) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Connection not available", getApplicationContext());
} else if (nResultCodeFromServer == CStaticVar.m_kTIMED_OUT) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Timed Out", getApplicationContext());
} else if (nResultCodeFromServer == CStaticVar.m_kTECHNICAL_FAILURE) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Technical Failure", getApplicationContext());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Server Error:-" + error);
m_Dialog.dismiss();
if (m_SwipeRefresh.isRefreshing()){
m_SwipeRefresh.setRefreshing(false);
}else {
m_Dialog.dismiss();
}
if (error instanceof TimeoutError) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Connection time out! please try again", getApplicationContext());
} else if (error instanceof NetworkError) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "No Internet connection", getApplicationContext());
}
}
});
requestQueue.add(jsonObjectRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
Define this variable in your activity
boolean isShowProgressDialog=true;
m_SwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
isShowProgressDialog=false;
getWalletBalance();
}
});
private void getWalletBalance() {
CLoginSessionManagement s_oSessionManagement = new CLoginSessionManagement(getApplicationContext());// making object of Registartion session management
// retreive user data from shared preferencce........
HashMap<String, String> user = s_oSessionManagement.getLoginDetails();// getting String from Regisatrtion session
String m_szMobileNumber = user.get(CLoginSessionManagement.s_szKEY_MOBILE).trim();
String m_szEncryptedPassword = user.get(CLoginSessionManagement.s_szKEY_PASSWORD).trim();
try {
String json;
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.put("agentCode", m_szMobileNumber);// sending mobile no.(static right know becuse of ser side data on other is null
jsonObject.put("pin", m_szEncryptedPassword);// same here as said above
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
Log.i(TAG, "Server request:-" + json);
if(isShowProgressDialog){
isShowProgressDialog=true;
m_Dialog = DialogUtils.showProgressDialog(getApplicationContext(),"Fetching wallet details...");
}
final String s_szWalletURL = "http://metallica/getWalletBalanceInJSON";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, s_szWalletURL, jsonObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.e(TAG, "Server Response:-" + response);
if (m_SwipeRefresh.isRefreshing()){
m_SwipeRefresh.setRefreshing(false);
}else {
if(m_Dialog!=null && m_Dialog.isShowing()){
m_Dialog.dismiss();}
}
try {
int nResultCodeFromServer = Integer.parseInt(response.getString("resultcode"));
if (nResultCodeFromServer == CStaticVar.m_kTRANSACTION_SUCCESS) {
s_szWalletBalance = response.getString("walletbalance").trim();// get wallet balance fro response
String trimwalletBalance = s_szWalletBalance.substring(0, s_szWalletBalance.indexOf("."));// trim waalet balance from response.
CWalletDataModel.getInstance().setS_szWalletBalance(trimwalletBalance);// set wallet balance
// showing wallet transaction in textView....
m_WalletText.setText(CWalletDataModel.getInstance().getS_szWalletBalance());
} else if (nResultCodeFromServer == CStaticVar.m_kCONNECTION_NOT_AVAILABLE) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Connection not available", getApplicationContext());
} else if (nResultCodeFromServer == CStaticVar.m_kTIMED_OUT) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Timed Out", getApplicationContext());
} else if (nResultCodeFromServer == CStaticVar.m_kTECHNICAL_FAILURE) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Technical Failure", getApplicationContext());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Server Error:-" + error);
m_Dialog.dismiss();
if (m_SwipeRefresh.isRefreshing()){
m_SwipeRefresh.setRefreshing(false);
}else {
if(m_Dialog!=null && m_Dialog.isShowing()){
m_Dialog.dismiss();}
}
if (error instanceof TimeoutError) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Connection time out! please try again", getApplicationContext());
} else if (error instanceof NetworkError) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "No Internet connection", getApplicationContext());
}
}
});
requestQueue.add(jsonObjectRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
Set a variable to mark if the swipe refreshing is going on like this.
private boolean isRefreshing = false;
m_SwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
isRefreshing = true; // Set the swipe refresh to true
getWalletBalance();
}
});
/* Here in this method we send request to server for wallet balance */
private void getWalletBalance() {
CLoginSessionManagement s_oSessionManagement = new CLoginSessionManagement(getApplicationContext());// making object of Registartion session management
// retreive user data from shared preferencce........
HashMap<String, String> user = s_oSessionManagement.getLoginDetails();// getting String from Regisatrtion session
String m_szMobileNumber = user.get(CLoginSessionManagement.s_szKEY_MOBILE).trim();
String m_szEncryptedPassword = user.get(CLoginSessionManagement.s_szKEY_PASSWORD).trim();
try {
String json;
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.put("agentCode", m_szMobileNumber);// sending mobile no.(static right know becuse of ser side data on other is null
jsonObject.put("pin", m_szEncryptedPassword);// same here as said above
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
Log.i(TAG, "Server request:-" + json);
// Add a check here
if(isRefreshing) m_Dialog = DialogUtils.showProgressDialog(getApplicationContext(),"Fetching wallet details...");
final String s_szWalletURL = "http://metallica/getWalletBalanceInJSON";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, s_szWalletURL, jsonObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.e(TAG, "Server Response:-" + response);
// Reset the value here
isRefreshing = false;
if (m_SwipeRefresh.isRefreshing()){
m_SwipeRefresh.setRefreshing(false);
}else {
m_Dialog.dismiss();
}
try {
int nResultCodeFromServer = Integer.parseInt(response.getString("resultcode"));
if (nResultCodeFromServer == CStaticVar.m_kTRANSACTION_SUCCESS) {
s_szWalletBalance = response.getString("walletbalance").trim();// get wallet balance fro response
String trimwalletBalance = s_szWalletBalance.substring(0, s_szWalletBalance.indexOf("."));// trim waalet balance from response.
CWalletDataModel.getInstance().setS_szWalletBalance(trimwalletBalance);// set wallet balance
// showing wallet transaction in textView....
m_WalletText.setText(CWalletDataModel.getInstance().getS_szWalletBalance());
} else if (nResultCodeFromServer == CStaticVar.m_kCONNECTION_NOT_AVAILABLE) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Connection not available", getApplicationContext());
} else if (nResultCodeFromServer == CStaticVar.m_kTIMED_OUT) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Timed Out", getApplicationContext());
} else if (nResultCodeFromServer == CStaticVar.m_kTECHNICAL_FAILURE) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Technical Failure", getApplicationContext());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Server Error:-" + error);
m_Dialog.dismiss();
if (m_SwipeRefresh.isRefreshing()){
m_SwipeRefresh.setRefreshing(false);
}else {
m_Dialog.dismiss();
}
if (error instanceof TimeoutError) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "Connection time out! please try again", getApplicationContext());
} else if (error instanceof NetworkError) {
CSnackBar.getInstance().showSnackBarError(m_MainLayout, "No Internet connection", getApplicationContext());
}
}
});
requestQueue.add(jsonObjectRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}

Categories

Resources