Friday 15 July 2011

Simple android app + database: what do I need in my android application? (PostgreSQL, REST API) -


I am preparing a simple Android app that gives prizes based on a prize, which tells the user. Each person should have their own user names, passwords, reward points, and wishlist items etc.

I am planning to use a PostgreSQL database on Hariokok, and I am writing the REST API on Heroki.

Now I'm not really sure what I want in my Android app? (Other than code)

1) Do I need another rest API?

2) Do I need another database?

3) Application communication with the REST API (which communicates with PostGraySQL on Heroko)? - & gt; Is it necessary to write a Java code for this?

Thanks a lot, the beginning of the day is taking a hard time finding the right resources: (

1) Do I need another rest API?

You only need one API which will serve as the gate in front of your data.

2) Do I need another database?

No, you do not need other databases. If you get a requirement to use the local requirement, you can use an SQLite instance or use an SD card Start considering the storage, where the preference can also be an option.

3) Does my Android app communicate with the REST API (which communicates with PostGraySQL on Heroko)? - & gt; Do I have to type Java code for this code?

You can use HttpClient to call the service after it is created. There are many instances on the web, one such example can be found once you interact with your API, it will later call the database through a DAL or other intangible layer and return the requested data.

  Public Class RestClient {Private ArrayList & lt; NameValuePair & gt; Parameter; Private Arrestist & lt; NameValuePair & gt; Header; Private string url; Private Ent Response Code; Private string message; Private string feedback; Public string getResponse () {return response; } Public string getErrorMessage () {return message; } Get public int spacing () {return responseCode; } Public RestClient {string URL} {this.url = url; Parameters = new arreelist & lt; Named Wolopleyre & gt; (); Header = new arreelist & lt; NameVailPayer & gt; (); } Public Zero AddParam (string name, string value) {params.add (New BasicNameValuePair (name, value)); } Public Zero AddHeader (string name, string value) {headers.add (New BasicNameValuePair (name, value)); } Public Zero executed (Request method method) throws an exception {switch (method) {Get the case: {// Junk parameter string combined Params = ""; If (! Params.isEmpty ()) {combinedParams + = "?"; (NameValuePair p: parameter) {string paramString = p.getName () + "=" + URLEncoder.encode (p.getValue (), a ???? UTF-8a ?? ³); If (combined param length ()> 1) {joint mercury + = "& amp; + paramstring;} and {joint mercury + param = main}}}} httpget request = new html gate (url + composite param); // Add headers to name (nameValuePair h: header) {request.addHeader (h.getName (), h.getValue ())}} ExecuteRequest (request, url); breakdown;} case post: {http post request = new http Add Headers to Name (NameValuePair h: Header) {request.addHeader (h.getName (), h.getValue ());} If (! Params.isEmpty ()) {request.setEntity (New UrlEncodedF OrmEntity (params, HTTP.UTF_8)); ExecuteRequest (request, URL); breakdown;}}} Private Zero Execute Request (HttpUriRequest Request, String URL) {HttpClient Client = New DefaultHttpClient (); HTTPRPSPTTPRPS; {HttpResponse = client Try .execute (request); ResponseCode = httpResponse.getStatusLine (). GetStatusCode (); Message = httpResponse.getStatusLine (). GetReasonPhrase (); HttpEntity unit = httpResponse.getEntity (); If (unit! = Null) {InputStream instream = entity.getContent (); Reaction = convertstreamstustring (instream); // Instream.close () release connection from closing the input stream; }} Catch (Client Protocol Exception e) {client.getConnectionManager (). shut down (); E.printStackTrace (); } Hold (IOException e) {client.getConnectionManager (). Close (); E.printStackTrace (); }} Private Static String ConvertStreamToString (InputStream) {Buffer Reader Reader = New Buffered Reader (New Interstitial Reader)); Stringbilder sb = new stringbiller (); String line = null; Try {{line = reader. Readline ()) = = null {sb.append (line + "\ n");}} grip (IOException e) {e.printStackTrace ();} Finally {try { Is.close () is;} hold (iOException e) {e.printStackTrace ();}} return sb.toString ();}}    

No comments:

Post a Comment