Below I explained what I need and in the answer I would like to get information what technology, what kind of protocols, services etc should I use.
Also I know that there is a massive amount of information on the internet, but because there are so many choices I'm unable to make a decision. Here's what I want to have:
Android application which will sent and receive information from the internet/server
Of course server, which will do some rudimentary computation with the obtained information, then store it and at the end send it back to the client application
I have to admit that the subjects of networking, socketing, protocols, ciphering etc are the ones I've always run away from. Therefore advices such as what domains, databases etc utilize are highly welcome
Update: After a bit of a research I've implemented mechanism based on information from this site [1]. I already have a working MySql database with several tables inside. Also I've added php scripts to my Apache webspace and implemented all that's necessary within my Android app.
Now, as I understand communication between php's scripts and MySql database is safe (I've hardcoded the usr/pass within scripts). Therefore the only thing that has left to be done to secure the connection between my Android application and php scripts (I want to prevent the situation when everybody has an access to my php scripts). So my question should be pretty straightforward now, how can it be achieved?
[1] http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/
I think a simple TCP/IP connection via Sockets will do just fine for your purposes.
The lesson (with more information and some examples) from the Java-Docs can be found here.
The basic workflow is as follows:
Your Android-App opens a Socket-connection to your server on a
given port where a server-application listens.
The Android-App sends it's data (whatever that might be) to the
Server.
The Server reads the send data,
processes it,
stores it...
...then it sends back some response (maybe the computed values) to your
Android-App.
Your app can then figure out if everything went okay and use the
given data.
Answering my second question, all the php scripts has been put into directory with the password on my Apache server. To be able to trigger them I need to give this password which is hardcoded in my application. All the connection is done through HTTPS. Now everything works as planned!
Related
I have started working on an Android app for which we need to use MySQL as database and Ruby on Rails for server side code. We will be using SQLLite too on device(will sync both DB as and when required). I searched the web and couldn't find any relevant tutorials/examples which can serve as a base to start with.
I have gone through MySQL and ROR tutorials but still has confusion on connecting Android with ROR.
Can somebody share some relevant tutorials/code snippet which can explain the complete linkage of the technologies. I mean how to send data from Android device to MySQL and vice versa. I know the concept theoretically but not sure how and where to start with.
My sincere apologies for asking such a basic question or if I sound ambiguous but I am a beginner and need to complete this task. Thanks in Anticipation..
Here is a brief overview of what you should know to accomplish your goal. I am not going to go that far into detail, especially since I have never personally used RoR. Note that some of these parts might not relate exactly to RoR, but the general idea behind it still applies. I will leave it up to you to research and figure out how to implement each individual component.
The general flow of everything is as follows:
Android App <==> Network <==> Web Service <==> MySQL
Note the double-edged arrows since data will be flowing in both directions.
The Android App is the client, and the Web Service and MySQL database are located on your Web Server. I only included the Network part for completeness, but you shouldn't have to do anything once the data has been sent onto the network.
A brief overview of each section:
Android App:
The Android App is the client that sends and retrieves data from the Web Server. I am assuming that in your app you are going to allow the user to do some tasks which in essence becomes the data that you want to send to the server at some point.
Take for example, the user should be able to enter his name and favorite animal. Lets say that there is an actual "Submit" button that the user may click. When this "Submit" button is clicked, it should wrap up the data into a proper format to be sent across the network. Two of the most common ones are JSON and XML. Once the data has been formatted properly, you will want to send the data to the server using some type of network protocol such as HTTP. In order to send the data, you of course must have some URL as the target. Lets say the target is www.example.com/webservice.php. This target is our Web Service located on the Web Server.
Once you send the data, the server will respond with some data at which point you can do whatever you want with it. Maybe display it to the user, or stick it in an SQLite database, or even both.
The key thing to remember is that there is no magic going on. Everything I have just described will be implemented in Java code that you will write in your Android Application at some point.
Key Ideas you should research more and figure out how to implement in Java code:
JSON and XML
HTTP in Java
REST and SOAP
Here is an excellent video on possible ways to set up the structure of your Android App.
Make sure that you are doing all network operations in your Android App on a different thread. An easy to use method is an Intent Service.
Web Service:
This is often the most confusing part. A Web Service is simply some entry point for clients attempting to access the Web Server. My explanation here might different slightly when using RoR, but the same idea applies. Notice above that the target URL was www.example.com/webservice.php. The web service is literally the PHP code that exists on the Web Server, called webservice.php. In your Android App, when you send data to the target URL using HTTP, the Web Service code will be executed on the server (and also have access to the data that you sent to it). Inside of your Web Service code, you will basically be extracting the data (which is in some format like JSON), grabbing the necessary parts, and then doing something with it. In this case you will most likely be querying the database. In PHP it is easy to write code that connects and queries a MySQL database that is also running on the server. When the response of the database is retrieved by the Web Server, you can send it back to the Android App. Just as before, remember, there is no magic going on. All of these ideas are implemented by writing some code.
Main ideas to research:
Ruby on Rails web service
How to access a MySQL database using Ruby on Rails
MySQL Database:
This is where you will store the data on the Web Server. I am not going to go that in depth here because this is just going to require you doing a lot of reading up on how to set up a MySQL database on a web server. It is also important that you learn how to create the appropriate queries such as SELECT, INSERT and so forth.
Main Ideas to research:
How to setup a MySQL database on a web server
If you need any clarification, let me know!
i was trying to build an app which takes the data from server database and use it in android app ( in may case for reading the gprs coordinates available on database).
after a lot of search, i came across RESTfull services for implementing this. but there is a simpler way also, that is accessing the server database directly from android app by using a driver (jtds) and running mysql on server side.
i am actually confused which one to use. Why restful service which is highly platform independent and have a wide range or directly accessing the mysql database from server. which is most extensively used and why? giving below examples of both scenarios.
through restful service - http://avilyne.com/?p=105 and directly by accessing sql server database- http://amitku.wordpress.com/2011/08/03/how-to-connect-and-access-sql-database-server-from-android-app/
please let me know which is better and mostly used and why?
I would strongly encourage using the REST approach, and although there are many reasons, two or three come immediately to mind:
1.) Security. By using a REST approach, any data on the server side can only be accessed by server-side code, which can provide a protective layer between the data and the outside world.
2.) Scalability. A direct connection, such as the example at your link, hooks into a particular instance of a database. If that database already has a large number of connections, there will be performance issues or worse.
3.) Server side flexibility. If the underlying database structure or technology needs to change, a REST approach will allow for that. All the client side cares about is posting or requesting to a server that will respond via REST protocol.
I would think that a REST approach is much more widely used than a direct client-server approach.
I have profiles in my mobile app and in web project. We are currently thinking about how can we synchronize them. The point is, if person add something to mobile profile - we can just send a bundle of ids to webserver and server will add them as well. The same with removing items. But what is if person will removes in mobile profile without constant connection, then removes something inside his profile in webserver`s profile? And after that we have to synchronize it somehow.
I understand that solution of such issue has to be already found, but unfortunately I didn`t find anything helpful yet.
I'd recommend watching Virgil Dobjanschi's Google I/0 2010 talk on designing RESTful client applications: here. It's about an hour long, but very informative and helpful.
Some key points to note are:
Use a SQLite database to act as a cache between your application and the webserver, so changes can be saved even there is no connection, then sent/received once you gain connection again.
Use a Service to handle REST calls, as it won't be restricted by a single Activity's lifecycle. This way your server requests can still be executed and properly handled if a user or the Android OS kills your Activity, a phone call pushes your application off the screen, etc. I'm using an Intent Service, as it handles threading for you.
You also need to determine which syncing relationship is most suitable for your application. What I mean by that is "Which database should overwrite the other: The SQLite or the webserver?". So when there are differences between the two, which data should be deemed "correct"? This is commonly referred to as master-slave.
I am trying to make an android app that requires a user to login against a MS SQL Database.
Having read around the most popular way seems to be to use JSON to do this however I'm not sure how secure this would be (especially if there is no SSL being used).
My question is what are the alternatives available and if JSON is the best/easiest way to achieve this how can I make it more secure? Is this also how big companies (such as dropbox etc) do this?
When I first started Android programming I was told that making a direct connection to the database is considered bad practice, and that an interface (JSP, PHP, .NET) should always be used. I don't know if this is a security thing or not but it would probably be the best for you.
If possible, create a .NET (or whatever server-side language you are comfortable with; .NET would probably be the easiest if you're working with a MS SQL server) page and talk to it over HTTPS (there's your security) and pass it the login info using POST. You could use JSON but name value parameters would accomplish the same thing. Have your page connect to the DB and test the information you pass it against whatever is in it. Then pass back a value that says whether it is correct or not in the response.
EDIT:
This looks like a decent guide to getting HTTPS set up on Android (just browsed through it quickly so I can't vouch for it 100%).
JSON is just the form you pass data in.
Noone stops you from using SSL for the connection. Or encrypting the JSON data in your own way.
I am supervising a project done by two students that involves retrieving information from a server and displaying it on an android phone. The students have never learnt networking, sql or java before (although they do know how to program) and are only now learning how to setup socketed connections between the phone and a sample server app that i gave them.
They will need to setup a simple sql database on the server on the campus network and be able to communicate with it and only pull information from the database and display it on the phone.
My current plan is that they will receive xml objects generated on the server side sent as a stream through the socket connection. They will then be able to generate a DOM using javax.xml classes and display it as they see fit on the phone itself.
Is this a valid method? What kind of problems can they expect to experience by following this technique? Is there another/better/correct way to do this (without using php or webservices)? The system will be for multiple users so will there be any significant performance issue with the proposed method?
Note 1: The phone never sends any request other than a single multicharacter identifier. The server interprets this identifier and returns information from preprogrammed queries and places it into an xml format.
Webservices sound like the correct approach for this, since you would not want to directly allow communication to the database over the internet.
The book "Unlocking Android" from Manning Publications, ISBN 978-1-933988-67-2 has a Chapter (6) dedicated to "Networking and web services".
Ah and then there is the one and only very nice video from a presentation regarding Android and RESTful webservices from the Google IO.
Couchbase, although from the NoSQL movement have a nice summary as well.
You could use JSON instead of XML, could be easier to parse and work with (feels more lightweight to me at least).
Sorry, forgot the answer for your search of problems:
Activity freezing upon freezing requests: Use additional threads for your requests
How to generally handle high latency
Handle offline behaviour