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 57a7548 commit eefd643
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,49 @@ 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
1. Create an object for FetchData class, pass the URL as argument. Don't forget to import the class.
```
String URL = "https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php";
FetchData fetchData = new FetchData(URL);
```
2. Start the fetching data.
```
fetchData.start();
```
3. Get the result as string.
```
String data = fetchData.getResult();
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
if (fetchData.startFetch()) {
if (fetchData.onComplete()) {
String result = fetchData.getResult();
Log.i("FetchData", result);
}
}
}
});
```

### Write data with POST and GET methods - PutData.class
1. Creating array for parameters
```
String[] param = new String[2];
param[0] = "param-1";
param[1] = "param-2";
```
_Use any parameter name that you like._

2. Creating array for data
```
String[] data = new String[2];
data[0] = "data-1";
data[1] = "data-2";
```
_Add as many as data and parameters as you like. Make sure number of parameters is equal to number of data. Also add them in exact order._

3. Create an object for PutData class, pass the URL as argument. Don't forget to import the class.
```
String URL = "https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php";
PutData putData = new PutData(URL, "POST", param, data);
```

4. Start the putData process.
```
putData.start();
```

5. Get the result as string.
```
String data = putData.getResult();
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
//Starting Write and Read data with URL
//Creating array for parameters
String[] param = new String[2];
param[0] = "param-1";
param[1] = "param-2";
//Creating array for data
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);
if (putData.startFetch()) {
if (putData.onComplete()) {
String result = putData.getResult();
progressBar.setVisibility(View.GONE);
textView.setText(result);
Log.i("PutData", result);
}
}
//End Write and Read data with URL
}
});
```

This is just like a pre-release version there are lot of other features coming soon.
Expand Down

0 comments on commit eefd643

Please sign in to comment.