public void onSuccess(String response) { try{ Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show(); JSONObject obj = new JSONObject(response); if(obj!=null) { JSONArray data = obj.getJSONArray("CheckForDuplicateSerialResult"); for(int i=0;i<data.length();i++) { JSONObject user = data.getJSONObject(i); String name=user.getString("Res"); if(name.equals("0")){ Toast t=Toast.makeText(getApplicationContext(), "Scan Next", Toast.LENGTH_SHORT); t.setGravity(Gravity.CENTER, 0, 0); t.show(); } else{ Toast.makeText(getApplicationContext(), "Already exist", Toast.LENGTH_SHORT).show(); } } } }catch(JSONException e){ Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } @Override public void onFailure(int statusCode, Throwable error,String content){ //Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show(); if(statusCode == 404){ Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show(); } else if(statusCode == 500){ Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show(); } else{ //Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show(); //Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show(); } } }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)