44
55Making HttpURLConnection easy and secure. Best method to impliment httpurlconnection in android.
66
7+ * [ Download demo apk and see how it works.] ( https://github.com/VishnuSivadasVS/Advanced-HttpURLConnection/releases/download/1.1/AdvancedHttpUrlConnection-debug.apk )
8+
79## Steps to add the library to your project.
810
911* Add it in your root build.gradle at the end of repositories:
@@ -17,57 +19,57 @@ allprojects {
1719* Add the dependency
1820```
1921 dependencies {
20- implementation 'com.github.VishnuSivadasVS:Advanced-HttpURLConnection:1.0 '
22+ implementation 'com.github.VishnuSivadasVS:Advanced-HttpURLConnection:1.1 '
2123 }
2224```
2325## Methods and how to use them
2426We have Two classes FetchData and PutData. Import the Library to your file first (In android studio paste the code and press alt + enter).
2527### Read Data From a URL - FetchData.class
26- 1 . Create an object for FetchData class, pass the URL as argument. Don't forget to import the class.
27- ```
28- String URL = "https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php";
29- FetchData fetchData = new FetchData(URL);
30- ```
31- 2 . Start the fetching data.
3228```
33- fetchData.start();
34- ```
35- 3 . Get the result as string.
36- ```
37- String data = fetchData.getResult();
29+ //Start ProgressBar first (Set visibility VISIBLE)
30+ Handler handler = new Handler();
31+ handler.post(new Runnable() {
32+ @Override
33+ public void run() {
34+ FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
35+ if (fetchData.startFetch()) {
36+ if (fetchData.onComplete()) {
37+ String result = fetchData.getResult();
38+ //End ProgressBar (Set visibility to GONE)
39+ Log.i("FetchData", result);
40+ }
41+ }
42+ }
43+ });
3844```
3945
4046### Write data with POST and GET methods - PutData.class
41- 1 . Creating array for parameters
42- ```
43- String[] param = new String[2];
44- param[0] = "param-1";
45- param[1] = "param-2";
46- ```
47- _ Use any parameter name that you like._
48-
49- 2 . Creating array for data
50- ```
51- String[] data = new String[2];
52- data[0] = "data-1";
53- data[1] = "data-2";
54- ```
55- _ 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._
56-
57- 3 . Create an object for PutData class, pass the URL as argument. Don't forget to import the class.
58- ```
59- String URL = "https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php";
60- PutData putData = new PutData(URL, "POST", param, data);
61- ```
62-
63- 4 . Start the putData process.
64- ```
65- putData.start();
66- ```
67-
68- 5 . Get the result as string.
6947```
70- String data = putData.getResult();
48+ //Start ProgressBar first (Set visibility VISIBLE)
49+ Handler handler = new Handler();
50+ handler.post(new Runnable() {
51+ @Override
52+ public void run() {
53+ //Starting Write and Read data with URL
54+ //Creating array for parameters
55+ String[] param = new String[2];
56+ param[0] = "param-1";
57+ param[1] = "param-2";
58+ //Creating array for data
59+ String[] data = new String[2];
60+ data[0] = "data-1";
61+ data[1] = "data-2";
62+ PutData putData = new PutData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/putDataTest.php", "GET", param, data);
63+ if (putData.startFetch()) {
64+ if (putData.onComplete()) {
65+ String result = putData.getResult();
66+ //End ProgressBar (Set visibility to GONE)
67+ Log.i("PutData", result);
68+ }
69+ }
70+ //End Write and Read data with URL
71+ }
72+ });
7173```
7274
7375This is just like a pre-release version there are lot of other features coming soon.
0 commit comments