Skip to content

intsab/Server-Calls-Android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Server Calls Introduction

Server Calls is a free Library for Http POST and GET requests for Android. You can upload file also in very simple way.

USAGE

Step 1- Simple Download the library folder
Step 2- Import in your project as module
Step 3- Add ``` android { useLibrary 'org.apache.http.legacy' } ```

in your gradle file of project. (if not exist*)

Post Request

 ArrayList<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("username", "10"));
        params.add(new BasicNameValuePair("password", "0"));
        NetworkCalls.getInstance().postRequest("http://xyz.com/api/login/format/json", params, new NetworkCalls.ResponseListener() {
            @Override
            public void onResponse(final String response) {
                Log.d("", response);
                MainActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Log.d("Response:",response);
                    }
                });

            }

            @Override
            public void onErrorResponse(String error) {
                Log.d("Error:",error);
            }

        });

GET Request

  NetworkCalls.getInstance().getRequest("http://xyz.com/api/getEvents/?limit=10&offset=0", new NetworkCalls.ResponseListener() {
            @Override
            public void onResponse(final String response) {
                Log.d("", response);
                MainActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Log.d("Response:",response);
                    }
                });
            }

            @Override
            public void onErrorResponse(String error) {
                Log.d("Error:",error);
            }
        });

Upload File with Parameters Request

  ArrayList<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("token", "22c61949efb02fd66c446f24dc680078"));
        params.add(new BasicNameValuePair("type", "profile"));
        File file = new File("/storage/sdcard0/DCIM/Camera/img.jpg");
        NetworkCalls.getInstance().uploadFileRequest("http://xyz.com/api/uploadProfile/format/json", file, "profile_pic", params, new NetworkCalls.ResponseListener() {
            @Override
            public void onResponse(String response) {
               Log.d("Response:",response);
            }

            @Override
            public void onErrorResponse(String error) {
                Log.d("Error:",error);
            }
        });

Developers

M Intsab Haider (Mobile & Web Application Developer)

About

Server Calls Android Library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages