I am trying to build a social app in which people can share their thoughts, like others' thoughts and comment also. I have a server and android app on client side as for now. My problem is that I want to make sure that user sees everything fresh each time activity is loaded such that server and client both can handle that much load. How do I determine how much data user has actually read from data sent by server and tell that to server so that server can keep check on what to send next?
One example I can think of is quora. It generates new feed each time although show how much i have read before at the end.
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 just can't get my head straight about this one. I'm currently building a rather large-scale application on Android. I've run in to a couple of problems regarding security and authentication though...
The Scenario:
I have an application that's making calls through HTTP (will implement SSL later) to a server running PHP and MySQL. Of course i want to use the existing user-database, so migration to another DB is not a solution..
I've managed to create the "register users via Android to the server"-functionality.
I've also made a working login, BUT this is where the problems start.
As users in the Android application I'am working on adds, edits, deletes and sync stuff on the server via/to the application, things get rather complicated. A little too complicated for me it seems :)
Problems:
As I get the result from my server-side login and pass it from the
server to Android via JSON, the connection dies and server-side I
'aint logged-on (sessions dies) whereas on the phone I'am. How can I
make the log-on persistent both on the server and in Android without
the need to log-on again? So that subsequent calls from Android to
the server is made with the same user, still authenticated. I.e. I
want sort of a one-time login ('till I logout) like in the
Spotify-app (and many others).
If I've understood things right, implementing SSL correct makes it
possible to send passwords in clear text to the server without the need to hash them first. Is this correct?
I just can't stop thinking about the fact that a MIM-attack would compromise any unique id I send from Android to the server. My first thought was to have the UID on the Android device as a "key" to the server after a successful log-on. But if that key gets in the wrong hands, the user associated with that UID will be compromised. I've looked at the AccountManager on Android but it seems rather over-kill in my case.
If someone could supply examples or at least guidelines, I'd be much grateful!
Thanks in advace!
ADDED SOLUTION DIAGRAM AFTER EDIT
Notice that this diagram shows the first start of the application. Later startups will NOT show the Login / Register form, but use the DUT instead.
// Alexander
Issue some form of a short-lived authentication token to Android apps. They would need to pass it in every request, and you will check it your Web app. Breaking the connection doesn't end the session, if it does, you have bug in your Web app: fix it. In Android, as long as you are using the same HttpClient instance, it will continue to use the same session, nothing special is needed.
Whatever you do, do not put off implementing SSL, do it now.
I've built some pretty straight forward apps earlier using phonegap for android.
Now i'm building one that will need statusbar notifications from a background service per user.
Using phonegaps backgroundservice plugin, im able to get notifications through the example twitter feed.
getMethod = new
HttpGet("http://search.twitter.com/search.json?q=phonegap&rpp=1&page1");
It works as expected, but i'm having big troubles with it.
1 - im not good with json
2 - ive yet to figure out how to store user credentials( user id f.example) on phone.
So lets say i want to build my own json file, myjson.php. in my java class, i cant pass a userid since this is not stored locally, and im unable to fetch it. my httpget would be:
getMethod = new
HttpGet("http://domain.com/myjson.php");
Myjson.php would serve me any new messages, so i have to have a way of specifying which user is requesting the file. Concidering it is all through sql, it has to be the same values.
php sessions wont cut it as phones often clears caches and forgets user credentials.
How can i do this? local sql? xml?
And if i manage to store the user credentials locally, how can i add these to my httpget request?
Any help and pointers are greatly appreciated as ive read and read and read and now = stuck.
You can store data locally using LocalStorage. It's very simple. (Link: https://developer.mozilla.org/en-US/docs/DOM/Storage)
Your first problem is you dont really do json. You just ask for a content encoded in Jason. Look at the native code contained here.
we have a text file stored on our server where I work, and I have searched on how to read in a specific line from that text file and have it display on the screen of my Android activity... but I haven't found a solution yet. Only two words, or so, of the text in the file on the server will be changed/replaced periodically, and I would like those changes to take effect/be updated in my Android app each time. Not sure why I couldn't find an answer to this yet. Any help is much appreciated! Thank you!
Actually the best way to have a secure transaction between an android app and server is to use web service like JSON. You request something from your android app to server, Then in server request will be analyse and response to your android app. You can send some request that tell the server what to do. Then in server side have a script that do your job and send response to your android app.
I need help figuring out the best, cross-browser compatible way to "SAVE" user input and STORE them locally(offline mod) AND on a server(online). Program will be used by Android and iOS.
I want to know the best way to track user progress while the device is online OR offline.
Hello I have been researching AJAX, JSON, XMLHttpRequest, REST, Java, and HTML5 (specifically, localStorage).
The scenario: (Read a book online/offline, save page progress)
A user logs in to a Web Service and the Web Service allows the user to download an "html webpage book" (view with HTML5 browser).
After every page turn, a REST API uses a GET request to post the Progress data to a Web Server. Simultaneously, a JSON string is created and saved in a file on the server. (let's say "ProgressData.txt")
In the background, a separate "copy" of ProgressData.txt is saved LOCALLY on the mobile device. The user then leaves the internet connection and continues to read the HTML Book.
When the user regains connectivity, the ProgressData.txt is uploaded to the server using a REST API where it will update the old server file with the NEW .txt file with all of the user ProgressData.
Possible solutions:
HTML5 localStorage solution looks good. jQuery even simplifies it:
http://plugins.jquery.com/project/html5Storage
Straight Javascript looks good for Server-Side storage, however it doesn't have access to a mobile device's physical hard-drive, thus preventing any kind of offline saving.
Java applets look possible. Plus not sure how Java runs with Android/iOS.
I don't want to have to run a localhost(PHP/Apache/Python) from a mobiledevice every time the user goes offline, however that may be where the solution lies. I did stumble on this powerful tool: http://couchdb.apache.org/
Question:
I need to know the best way to track user progress while the device is online OR offline. What is the best way to do this?
I stumbled across store.js the other day which might help solve the cross browser local storage. It was from this article about local storage.
I think your best option for tracking online/offline is to ping the server via an AJAX call when the page is turned. Always try and update the server on a page turn, but if it fails, handle the failure and store the progress locally. Each page turn will either amend the locally stored progress file or if connection is restored then simply update the server with the progress.
The issue I am thinking might occur is if a book is finished offline then there are no more clicks that would trigger the syncing, regardless of a restored connection. You may want to think about a manual sync link/button at the end of a book. Or maybe have a manual sync available at all times anyway? Give some control to the users and describe the whole offline/online reading scenario. You might find that it is easier to just let the users do the work… if they don't sync then it's their problem!
Here are 2 screencasts what will help you with your problem.
They are in Ruby on Rails but maybe you can get the idea. It is using the html5 cache manifest.
Hope it will help you!
http://railscasts.com/episodes/247-offline-apps-part-1
http://railscasts.com/episodes/248-offline-apps-part-2
some more resources (sorry i dont have experiences myself with html5 cache manifest)
http://diveintohtml5.ep.io/offline.html
http://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html
I'd suggest just using a cookie to store the current state. That way it is automatically sent to your server with every user request (so no need to build out a custom server-side API for receiving the state after a lost connection, and no need to have any custom client-side code for sending the data to the server), and still updateable even if the user has lost Internet connectivity. Also it doesn't rely on HTML5 features, so you don't need to restrict people to HTML5-capable browsers.
In any case, the best way to handle storing the current state would be to have a simple onclick handler on your "next page" link (or button, or whatever it is) that calls a function and sets the cookie value to whatever the current position is. Note that because the state is always available client-side, and sent to the server on every request, there is no need to maintain any explicit copy of the state server-side, unless you want to be able to remember the user's place even when they manually delete their cookies (which is overkill in my opinion).
You may want to look at the W3C Example Code for setting/getting cookie values in JavaScript.
Also, here's a website that demonstrates functionality similar to what you want to build. It uses cookies to keep track of a user's place when reading various webcomics. Pretty much the same as what it sounds like you want, except with comics instead of books.
It would be wise to track the progress in both a server side database and in the client's local storage if a constant internet connection is not necessary.
Evercookie is a controversial javascript api that aims to provide local storage using any means available including standard cookies, Flash shared object, Silverlight, browser history and HTML 5 storage. Data should persist when the user is offline and when the connection is restored, sync the cookie and database with whichever data has greater page number for the given book. Droid has Flash and the Flash shared object data is a "cookie" available to both desktop and web-based apps.
With great power comes great responsibility:
http://samy.pl/evercookie/