Connection Database Online
Connection Database Online
1. WebServer
2. A Database Stored in the webserver
3. And a little bit android knowledge :)
4. Webservices (json ,Xml...etc) whatever you are comfortable with
2. Make a class to make an HTTPRequest from the server (i am using json parisng to get the
values)
for eg:
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return jArray;
}
}
3. In your MainActivity Make an object of the class JsonFunctions and pass the url as an
argument from where you want to get the data
eg:
JSONObject jsonobject;
jsonobject = JSONfunctions.getJSONfromURL("http://YOUR_DATABASE_URL");
4. And then finally read the jsontags and store the values in an arraylist and later show it in
listview if you want
and if you have any problem you can follow this blog he gives excellent android tutorials
AndroidHive
Since the above answer i wrote was long back and now HttpClient, HttpPost,HttpEntity
have been removed in Api 23. You can use the below code in the build.gradle(app-level) to still
continue using org.apache.httpin your project.
android {
useLibrary 'org.apache.http.legacy'
signingConfigs {}
buildTypes {}
}
or You can use HttpURLConnection like below to get your response from server
switch (status) {
case 200:
case 201:
BufferedReader br = new BufferedReader(new
InputStreamReader(c.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line+"\n");
}
br.close();
return sb.toString();
}