I have a project that consists of using snowtams for aviation(displaying and decoding snowtams) and i want to make a request to a server using my api key but when i put the full link on browser the response is not a body response but a json file which is downloaded every time i make the request.How can i handle this file in code in java using Android.Could you give me a sample example of this? and thanks in advance.
an example that i tried:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_snowtam_codes);
URL url = null;
try {
url = new URL("https://ajax.googleapis.com/ajax/services/feed/find?" +
"v=1.0&q=Official%20Google%20Blog&userip=INSERT-USER-IP");
} catch (MalformedURLException e) {
e.printStackTrace();
}
URLConnection connection = null;
try {
connection = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
connection.addRequestProperty("Referer", "https://applications.icao.int/dataservices/api/notams-
realtime-list?api_key=my_api_key&format=json&criticality=1&locations=ENBO");
StringBuilder builder = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
while(true) {
String line="";
try {
if (!((line = reader.readLine()) != null)) break;
} catch (IOException e) {
e.printStackTrace();
}
builder.append(line);
}
try {
JSONObject json = new JSONObject(builder.toString());
System.out.println("the json object received is::"+json);
} catch (JSONException e) {
e.printStackTrace();
}
}