diff --git a/README.md b/README.md index c0f9c91..5f44656 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,25 @@ allprojects { ## Methods and how to use them We have Two classes FetchData and PutData. Import the Library to your file first (In android studio paste the code and press alt + enter). ### Read Data From a URL - FetchData.class +You need to use Handler and post a Runnable. Inside the run method add the code for FetchData. + +* Creating the object for FetchData, pass the URL as argument. +``` +FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php"); +``` +* Calling startFetch() returns a boolean value. +``` +fetchData.startFetch(); +``` +* To know when the process is completes use onComplete() which returns a boolean value. +``` +fetchData.onComplete(); +``` +* If the process is complete, use the getResult() to get the result value. +``` +fetchData.getResult(); +``` +* Full implimentation with Handler. You can also add a progress bar at the commended regions. ``` //Start ProgressBar first (Set visibility VISIBLE) Handler handler = new Handler(); @@ -44,6 +63,40 @@ handler.post(new Runnable() { ``` ### Write data with POST and GET methods - PutData.class +You need to use Handler and post a Runnable. Inside the run method add the code for PutData. + +* First we need to create to arrays, one for field name of the parameter and another for the data. Make sure the order is correct. +``` +String[] param = new String[2]; +param[0] = "param-1"; +param[1] = "param-2"; +String[] data = new String[2]; +data[0] = "data-1"; +data[1] = "data-2"; +``` +* PHP representation, The post array will look like, +``` +$_POST['param-1'] = "data-1"; +$_POST['param-2'] = "data-2"; +``` + +* Creating the object for PutData, pass the URL, method, field, data as arguments. The method can be POST and also GET. +``` +PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data); +``` +* Calling startFetch() for starting the process, it returns a boolean value. +``` +putData.startFetch(); +``` +* To know when the process is completes use onComplete() which returns a boolean value. +``` +putData.onComplete(); +``` +* If the process is complete, use the getResult() to get the result value. +``` +putData.getResult(); +``` +* Full implimentation with Handler. You can also add a progress bar at the commended regions. ``` //Start ProgressBar first (Set visibility VISIBLE) Handler handler = new Handler(); @@ -59,7 +112,7 @@ handler.post(new Runnable() { String[] data = new String[2]; data[0] = "data-1"; data[1] = "data-2"; - PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "GET", param, data); + PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "POST", param, data); if (putData.startFetch()) { if (putData.onComplete()) { String result = putData.getResult();