Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect android app with the database from a Website

I need the users to register to my website with login and password.

basically i need to do the following

1.Connect android app with the database from a website.

2.Store some information into the database.

3.retrieve some information back from the database.

I have already experience with the standard sqlite build in android apps. The problem is, I need to let people register my website and retrive some information

like image 626
Goofy Avatar asked Mar 05 '12 07:03

Goofy


People also ask

How an Android app is connected to database?

Create a DatabaseCreate "SQLiteDatabase" object. Open or Create a database and create a connection. Perform insert, update or delete operation. Create a Cursor to display data from the table of the database.

Can I use the same database for website and mobile app?

Yes, you just need to use the Firebase config of same project.


2 Answers

To store or retrieve any information stored on a Database on a web server, you will need to create a simple web service that will pass the requests to the database and then return the results from the database back to Android in a format Android can understand. You can typically send the data in POST or REST and then retrieve the data in JSON format.

There is a very good example of how you could achieve that using PHP here. Here you would send requests from Android to the PHP script(hosted on the server) using POST and then the script would return the results in JSON format, which in turn can be parsed by Android to get the desired result.

This is the basic method in which complex web services like twitter, facebook and the like operate. Most of the interaction is done with REST & JSON.

like image 96
Soham Avatar answered Sep 19 '22 21:09

Soham


Usually you shouldn't directly connect to a database from an app because:

  • you have to store your database username/password in your app (everyone who is able to use a decompiler will get it very quickly)
  • once you have the username/password, you are able to do anything with the database

Based on these points I would recommend you to put a webservice between your app and the database. This webservice could be programmed in any programming language you like. It should protect your database from unintended requests on your database.

Your app then connects to your webservice, the webservice validates the user input and stores it in the database. When you'd like to receive some data from database, you just connect to the webservice and ask for data.

like image 21
SecStone Avatar answered Sep 23 '22 21:09

SecStone