Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSivadasVS authored Jun 24, 2020
1 parent 99e3670 commit 7ddd7bd
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ We have Two classes FetchData and PutData. Import the Library to your file first
### 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.
* Creating the object for FetchData, pass the URL as argument.
```
FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
```
Expand Down Expand Up @@ -63,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();
Expand All @@ -78,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();
Expand Down

0 comments on commit 7ddd7bd

Please sign in to comment.