Fetch data from any API to Sketchware app
Fetch data from API to Sketchware app
API -Application ProgrammingInterface
Ie; if we have an website contains a lot of data which is only can be displayed using WEBPAGE.
but as we became more advanced.
We need to display that data from Webserver to our Android application.
But we can't directly fetch data from Webserver to An android application.
This is where the use of API cames in.
Using API we can request data from Webserver and it will respond with JSON file that is easily accessible using Android app.
So here we are going to Fetch any online API/JSON file to android application and display it in Well designed manner.
To do this we need an Open/FREE API service provider.
So here am using OMDb API - An open movie database
You can register on there website to get a key to access the big Movie database HERE
After you get the key you will get a URL like this👇
http://www.omdbapi.com/?apikey={yourkey}&t={movie/series name}
Here you need to pass the Apikey and Movie name to get the JSON response.
More info refer the VIDEO.
ASD BLOCK'S
Code 1
new BackTask().execute(get);
Code 2
}
private class BackTask extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {}
protected String doInBackground(String... address) {
String output = "";
try {
java.net.URL url = new java.net.URL(address[0]);
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(url.openStream()));
String line;
while ((line = in.readLine()) != null) {
output += line;
}
in.close(); } catch (java.net.MalformedURLException e) {
output = e.getMessage();
} catch (java.io.IOException e) {
output = e.getMessage();
} catch (Exception e) {
output = e.toString();
}
return output;
}
protected void onProgressUpdate(Integer... values) {}
protected void onPostExecute(String s){
str= s;