How to know the webservice gets updated in android - android

I am missing some logic in my app. I am having json webservice which can be modiy by administrator.For the first launch of my app I am storing the data from the webservice and stores in sqlite and displays the data from sqlite using background threads.If it is second time launch then the app directly displays the sqlite data. Now the problem is if it is for the second time launch of the app how can I recognize the webservice got modified and where it is modified and how can I store the particular record?
For that I am comparing with the id's of the book in sqlite and webservice if new book enters I am able to get the new item and store it in the sqlite and display them from sqlite.But if there is any modifications in item details how can I recognize the particular tag?

Write a REST API on your web server that will send you a list of modified records. Query this API every time you start your app.
If there are modified records, This API should return you a list of the modified records which you can use to update your local sqlite database.
If not, then this API will return nothing and you can carry on happily :-)
You can create REST API's by writing server side code using a language like PHP, Ruby, Python etc
There are other options that avoid REST API's as well. See:
How to get from a MySql server to an Android app?
See here for a beginners tutorial on REST:
http://net.tutsplus.com/tutorials/other/a-beginners-introduction-to-http-and-rest/

Related

search through web-service with json

In my android application im using web-service to get information about food the problem that if i write appl instead of apple,row,skin it dosent fill automatically and an error message will be shown,, what i did i stored 2000 name from web service in sqlite and search through them is it wrong to do this ? and how can i search with misspelling in web-service without the error message ?
The api url http://api.nal.usda.gov/ndb/search/?format=json&q=apple&sort=n&max=25&offset=0&api_key=DEMO_KEY
Salam Enas,
If the data do change frequently (like a movies list) then it's not ok to store it in the sqlite and it's better to be stored in the server database.
If the data does not change frequently, then it's ok to store them on the sqlite database although the app size will increase by 2 Mb which is a drawback.
You may also want to consider other APIs if you are not committed to use this one.
When storing data on the server, HTTP requests burden can be alleviated by caching data on the mobile.
good luck :)

Real-time communication between app and webpage

I'm trying to figure out how to have a real time data displayed on a webpage through the use of an android app.
For example, users are using android app and are scored (answering questions). My webpage will display the scores in order in real-time.
Iv come to the conclusion to use Redis, but what exactly do i need for this to function? Do i need a web socket where my web page will communicate with. This socket could be python where it accesses the database and then responds with the scores in order?
Im struggling to find out how exactly this would work as this is new to me. What exactly should i be looking for (terminology etc)?
Thanks
One approach might be:
set up a database on a server on the internet
program your app to save data to that remote database
set up a webservice
program the webservice to read data from the database and serve it as an html page
For extra credit
implement a REST style API which retrieves and serves data from the database
create an ajax webpage which uses the API to fetch and display data (so you don't have to refresh the page constantly)

How do I update an Android app database data daily?

I'm developing an Android app I want to publish on Google Play that shows data from its internal database.
I'd like to insert new data in the app internal database once a day for the next n years, this operation should be done automatically from a program that scrapes the internet for new information.
So, when a user opens the app on his mobile, the app internal database has to be updated with the new data, if there is (without have to update the whole app).
Is there a solution?
Without a database on a server
I will outline my proposed architecture for your problem:
You should have a server with a database that will hold all your data and an api endpoint for the android client to get the updates. Something like
http://yourhost/get_updates?since=13435465345.
Then the server should use the 'since' param to query for data updates, something like
select * from news where updatedAt>:since
The server will generate a responce based on that query in your favorite format (json or xml) and return it to the client. The client will take the data and insert it in the local database, and store the current timestamp as an update point (to use is as future 'since' param)

Android/Web App offline/online Database setup. Creating items on both platforms

Read Update 1 for a beter question description. Sorry about that.
I'm trying to figure out how to build a Android App and Web App that syncs there data.
I know that I should make an REST API for the MySQL database to sync with the Android App.
I have made a App before that syncs data but only for retrieval (SELECT queries) on the android side.
I now want to make a Android App / Web App that should create/update items on both platforms and syncs so both have the new/updated items. The app should also work offline.
I'm used to creating id's for most database tables as key with autoincrement. Now that I'll have 2 databases i'm not sure how to create those unique IDs. Or should I ditch those id's and use a combination of columns as primary key (with a timestamp or something).
Hope it makes sence, english is not my native language.
UPDATE 1
Narowing the question:
So i have a MySQL database with an PHP API. The API will be used by the Web App and Android App.
Question is how to handle offline data creation in de android App. If you rely on a id with autoincrement of the MySQL Database.
Example: When creating a person how to get an id for that person (If the MySQL database handles ID creation)
Thanks in advance,
Otto Vanluchene
What you're asking is a very broad question and there's a lot of options, but this is how I do it.
HOW TO HANDLE NATIVE SIDE REST CALLS:
First of all I use an HTTP library to handle my GET/POST REST API calls. It handles the callbacks and can be super helpful.
This is the one I usually use:
LoopJ's Async HTTP Callback Library
This will handle GET and POST requests with a lot of cool features such as custom timeouts, JSON format, onSuccess() and onFailure() methods, etc. There's a lot of working examples of this library too. I've used it in all my apps and haven't had any problems yet!
DATABASE SETUP:
Your going to want to create a MySQL database to store all your data. You may want to read up on common DB practices.
API SETUP
I write all my APIs in PHP, but that's just my preference. The APIs you write here will be used in your web AND mobile apps to keep things consistent. Assuming you use GET, you can just pass an argument (which I usually call "callback") that will determine what chunk of information the API will return.
For example:
http://www.ottosite.com/otto_api.php?callback=get_users
So in your PHP code, you'll have it checking if callback=get_users, and if it does, it will query the database for all the users, format the json string, then simply echo it.
This may return something like:
{"status":"success","users":["user1","user2","user3"]}
So this is obviously a JSON formatted response, then in your app, when you call that API, you just parse the response into a JSONObject (JSONArray for users) and then grab whatever data you need from it.
Hopefully this helps.

Updating a SQL database on an Android app with data from an SQL database on a server

I need some help, my app created a database on creation at the minute.
What I want is to get the information in a database on a server or PC and load it into my app.
It just needs to be from server to app, not back again.
I have no idea how I would do this, does anyone have any ideas?
first, I should say that your question is so wide. It contains alot of technologies.
So, I'll give you a breif walk through here. you should figure out the rest on your own. and then, you can come back and ask more specific questions.
That said, here is the path you should take:
On the server, implement a REST API that respond to the caller with the data in the server database.
example: http://your.server.com/api/somedata
calling this url with GET method should return the data you want in JSON format.
from your android application, call this url and save the response in a String.
parse the JSON String ( you can use gson ).
save the parsed data to your local database.
If you are the one developing the server api, then this book is a recommended reading:
RESTful Web Services
Update
Say you have a table in your server database called (TABLE) with the columns COL_1, COL_2, COL_3.
You could implement a php page called 'TABLE.php' that return the following:
{
"items": [
{"COL_1": "value_1", "COL_2": "value_2", "COL_3": "value_3"},
{"COL_1": "value_2", "COL_2": "value_3", "COL_3": "value_4"},
{"COL_1": "value_4", "COL_2": "value_5", "COL_3": "value_6"},
...
]
}
In your android application call http://your.server.com/api/TABLE.php page with GET method, parse the JSON returned (above) and save it to your local database.
You can do this for each database table on your server, until you have all your data saved locally in your android application.
This probably wont be the best design decision, but considering your knowledge about the topics, this could be a fair starting point.
Using HttpClient you can set things up to execute a POST to some servlet or similar app on the server. That app needs to then send data back to your Android app which is waiting for a response from the server. Then your app can parse the data and stuff it's own database.

Categories

Resources