-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetchData.java
More file actions
53 lines (45 loc) · 1.58 KB
/
Copy pathfetchData.java
File metadata and controls
53 lines (45 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.ucfgarageparking;
import android.app.Activity;
import android.os.AsyncTask;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class fetchData extends AsyncTask <Void,Void,Void> {
String data ="";
String dataParsed = "";
String singleParsed = "";
@Override
protected Void doInBackground(Void ... voids) {
try {
URL url = new URL("https://parkingbuddy.herokuapp.com/testing/ENG1");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
while(line!=null) {
line = bufferedReader.readLine();
data = data + line;
}
JSONObject jo = new JSONObject(data);
singleParsed = "Gargage is" + jo.get("garage");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
MainActivity.data.setText(this.data);
}
}