Twitter Bird Gadget

Thursday 10 March 2016

Android volley post request to server and get JSON response

MyJSONRequestResponse.java

public void alldata_json_request(final String client_id, final String client_emailid) {

    StringRequest strReq = new StringRequest(Request.Method.POST,

            QBQueries.CLIENTSLIST, new Response.Listener<String>() {

        @Override

        public void onResponse(String response) {

            Log.e("response", "response" + response.toString());

            //msgResponse.setText(response.toString());

            // hideProgressDialog();

            try {

                Log.e("responseeeeee", "response" + response.toString());

                //hideProgressDialog();

                String alldata = "";

                JSONObject jsonObject = new JSONObject(response.toString());

                Log.e("response", "response" + jsonObject.toString());

                int success = jsonObject.getInt(TAGS.TAG_SUCCESS);

                Log.e("ss", "ss" + success);

                Log.e("clientres", "clientressssssss----" + client_uid + "" + client_emailid);

                if (success == 1) {

                    client_arraylist = jsonObject.getJSONArray(TAGS.TAG_CLIENT);
                    // successfully get clients details
                  
                  for (int i = 0; i < client_arraylist .length(); i++) {

                        JSONObject cget = client_arraylist .getJSONObject(i);

                        _client_id.add(cget.getString("client_id"));

                        _client_photo.add(cget.getString("client_photo"));

                        _client_fullname.add(cget.getString("client_fullname"));

                        _client_emailid.add(cget.getString("client_email"));

                        _client_relationship_status.add(cget.getString("client_status"));
                      
                    }


     _allclient_id=_client_id.toArray(new String[_client_id.size()]);

      _allclient_name=_client_fullname.toArray(new String[_client_fullname.size()]);

   _allclient_email=_client_emailid.toArray(new String[_client_emailid.size()]);
                  
   
mylist_adapter = new mycustomlist_adapter_clientdata(getApplicationContext(),
 _allclient_id, _allclient_name, _allclient_email);
//listview object
  mylistview.setAdapter(mylist_adapter);

                } else if (success == 0) {

   Toast.makeText(getApplicationContext(), "No Clients found.", Toast.LENGTH_SHORT).show();

                }

            } catch (JSONException e) {

                e.printStackTrace();

            }

        }

    }, new Response.ErrorListener() {

        @Override

        public void onErrorResponse(VolleyError error) {

            VolleyLog.d("Error: ", "Error: " + error.getMessage());

          Toast.makeText(getApplicationContext(), "Check Connectivity", Toast.LENGTH_LONG).show();

        }

    }) {

        //send parameter request to server

        @Override

        protected Map<String, String> getParams() {

            Map<String, String> params = new HashMap<String, String>();

            params.put("txtClient_pkid", client_id);

            params.put("txtClient_emailid, client_emailid);

            return params;

        }

    };

    // Adding request to request queue

    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

}



build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion
23
   
buildToolsVersion "23.0.2"

   
defaultConfig {
        applicationId
"com.test.vollyrequestapp"
       
minSdkVersion 14
       
targetSdkVersion 23
       
versionCode 1
       
versionName "1.0"
   
}



    buildTypes {
        release {
            minifyEnabled
false
           
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       
}
    }


}

dependencies {
    compile fileTree(
dir: 'libs', include: ['*.jar'])
    testCompile
'junit:junit:4.12'
   
compile 'com.android.support:appcompat-v7:23.1.1'
   
compile 'com.android.support:support-v4:23.1.1'
   
compile 'com.android.support:design:23.1.1'
   
compile files('libs/volley.jar')
    compile
'com.squareup.picasso:picasso:2.5.2'
   
compile files('libs/slider.jar')
    compile
'com.android.support:appcompat-v7:22.1.1'
   
compile 'com.android.support:cardview-v7:22.1.1'
   
compile 'com.android.support:gridlayout-v7:22.1.1'


}


Feel free to post your comments, queries and suggestions 
Cheers...:-)

No comments :

Post a Comment