I want to store contents of my local db to oracle cloud. I have searched the internet but cannot find any apis which can guide me to my result. The documentation is very naive and I cannot find a solution.
Been searching for 3 days, help would be appreciated
(Disclaimer: I work for the Oracle MCS team)
In response to your update that you want to store data in MCS.
Let's break this discussion into two parts, the MCS server side, and the client side which is Android in your case.
From a MCS server perspective you have two options for storage, the "Storage API" and the "Database API". The "Storage API" is designed to store files (aka. objects) in collections. The "Database API" is for more traditional data stored in RDBMS tables, columns & rows. So you need to make a choice which you think is more suitable for your needs.
Note that the Storage API is accessible external to MCS from a mobile client as a REST API, as well as node.js custom APIs within MCS that you would manually write. However the Database API is only accessible from node.js custom APIs. So if you choose to use the Database API you must also build server side custom APIs to expose the Database API to your client. With the Storage API it is already exposed to your client.
If we move onto the client side and what you need to do, you ultimately need to build your client to contact these server side APIs, which ever you choose as the description above. In building the client side you have two choices:
1) Manual - you create your own code to create, store and manage objects in the Android local db (eg. SQLLite), and then you need to write client side code to consume the MSC server APIs you've setup and read/write data from the local db. There is potentially significant work here, but, the MCS Android SDK will make this job easier as it provides client side libraries to call both the server side Storage API or Custom API (wrapping the Storage API or Database API) that we considered above, rather than you having to write raw REST calls.
2) Automatic - the MCS Android SDK also provide a "data offline & sync" SDK that takes care of the creation, store and management of objects in the device's database for you, and synchronising the data with the server side for you, based on a bunch of policies you pick. There is still some coding required, but mostly it's greatly reduced compared to the manual option above.
I'm sure you are already familiar with the MCS YouTube channel and it does cover how to build custom APIs, use the storage API, and does include videos on the Data Offline & Sync SDK too. Look to the playlists in the channel for the major topic areas. By chance I literally finished the Android video for Data Offline & Sync a couple weeks back (remember to watch the other data offline & sync videos before this one!), and it's not yet public. But you can have a sneak peak of the video here.
(A comment for future readers of this post: Please note that URL may change when we finally properly publish that video)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to sync data (such as db record, media) between an Android App and a Server. If you've seen Evernote or similar Applications, you certainly understand what I mean.
I have some question (imagine we want to sync DB records):
Every user has a part of server space for himself (such as Evernote or Dropbox). Maybe the user creates new records by cellphone and creates new records in server. How can I match these records together? If there are records with same ID What algorithms do you suggest me?
Except JSON, Are there any way for send data between cellphone device and server?
If SyncAdapter and ContentProvider can solve my problems, please explain exactly for me. (If you could offer some samples or tutorials to me OR Any advice or keywords to help broaden/guide my search would be appreciated as well).
I'll try to answer all your questions by addressing the larger question: How can I sync data between a webserver and an android app?
Syncing data between your webserver and an android app requires a couple of different components on your android device.
Persistent Storage:
This is how your phone actually stores the data it receives from the webserver. One possible method for accomplishing this is writing your own custom ContentProvider backed by a Sqlite database. A decent tutorial for a content provider can be found here: http://thinkandroid.wordpress.com/2010/01/13/writing-your-own-contentprovider/
A ContentProvider defines a consistent interface to interact with your stored data. It could also allow other applications to interact with your data if you wanted. Behind your ContentProvider could be a Sqlite database, a Cache, or any arbitrary storage mechanism.
While I would certainly recommend using a ContentProvider with a Sqlite database you could use any java based storage mechanism you wanted.
Data Interchange Format:
This is the format you use to send the data between your webserver and your android app. The two most popular formats these days are XML and JSON. When choosing your format, you should think about what sort of serialization libraries are available. I know off-hand that there's a fantastic library for json serialization called gson: https://github.com/google/gson, although I'm sure similar libraries exist for XML.
Synchronization Service
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
As for how you identify if the records are the same, typically you'll create items with a unique id which you store both on the android device and the server. You can use that to make sure you're referring to the same reference. Furthermore, you can store column attributes like "updated_at" to make sure that you're always getting the freshest data, or you don't accidentally write over newly written data.
If we think about today, accepted answer is too old. As we know that we have many new libraries which can help you to make this types of application.
You should learn following topics that will helps you surely:
SyncAdapter: The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.
Realm: Realm is a mobile database: a replacement for SQLite & Core Data.
Retrofit Type-safe HTTP client for Android and Java by Square, Inc. Must Learn a-smart-way-to-use-retrofit
And your sync logic for database like: How to sync SQLite database on Android phone with MySQL database on server?
Best Luck to all new learner. :)
If you write this yourself these are some of the points to keep in mind
Proper authentication between the device and the Sync Server
A sync protocol between the device and the server. It will usually go in 3 phases, authentication, data exchange, status exchange (which operations worked and which failed)
Pick your payload format. I suggest SyncML based XML mixed with JSON based format to represent the actual data. So SyncML for the protocol, and JSON for the actual data being exchanged. Using JSON Array while manipulating the data is always preferred as it is easy to access data using JSON Array.
Keeping track of data changes on both client and server. You can maintain a changelog of ids that change and pick them up during a sync session. Also, clear the changelog as the objects are successfully synchronized. You can also use a boolean variable to confirm the synchronization status, i.e. last time of sync. It will be helpful for end users to identify the time when last sync is done.
Need to have a way to communicate from the server to the device to start a sync session as data changes on the server. You can use C2DM or write your own persistent tcp based communication. The tcp approach is a lot seamless
A way to replicate data changes across multiple devices
And last but not the least, a way to detect and handle conflicts
Hope this helps as a good starting point.
#Grantismo provides a great explanation on the overall. If you wish to know who people are actually doing this things i suggest you to take a look at how google did for the Google IO App of 2014 (it's always worth taking a deep look at the source code of these apps that they release. There's a lot to learn from there).
Here's a blog post about it: http://android-developers.blogspot.com.br/2014/09/conference-data-sync-gcm-google-io.html
Essentially, on the application side: GCM for signalling, Sync Adapter for data fetching and talking properly with Content Provider that will make things persistent (yeah, it isolates the DB from direct access from other parts of the app).
Also, if you wish to take a look at the 2015's code: https://github.com/google/iosched
For example, you want to sync table todoTable from MySql to Sqlite
First, create one column name version (type INT) in todoTable for both Sqlite and MySql
Second, create a table name database_version with one column name currentVersion(INT)
In MySql, when you add a new item to todoTable or update item, you must upgrade the version of this item by +1 and also upgrade the currentVersion
In Android, when you want to sync (by manual press sync button or a service run with period time):
You will send the request with the Sqlite currentVersion (currently it is 1) to server.
Then in server, you find what item in MySql have version value greater than Sqlite currentVersion(1) then response to Android (in this example the item 3 with version 2 will response to Android)
In SQLite, you will add or update new item to todoTable and upgrade the currentVersion
Look at parseplatform.org.
it's opensource project.
(As well as you can go for commercial package available at back4app.com.)
It is a very straight forward and user friendly server side database service that gives a great android client side API
one way to accomplish this to have a server side application that waits for the data. The data can be sent using HttpRequest objects in Java or you can write your own TCP/IP data transfer utility. Data can be sent using JSON format or any other format that you think is suitable. Also data can be encrypted before sending to server if it contains sensitive information. All Server application have to do is just wait for HttpRequests to come in and parse the data and store it anywhere you want.
I would suggest using a binary webservice protocol similar to Hessian. It works very well and they do have a android implementation. It might be a little heavy but depends on the application you are building. Hope this helps.
#Grantismo gives a great overview of Android sync components.
SyncManagerAndroid library provides a simple 2-way sync implementation to plug into the Android Sync framework (AbstractThreadedSyncAdapter.OnPerformSync).
https://github.com/sschendel/SyncManagerAndroid
By using couchbase sync_gateway for mobile sync(android,ios) you can still use the database from custom server side app?
My application needs to run on both mobile and web. I have angularjs for browsers and nodejs/express for server side.
If I will update the database form browser->node->couchbase ... mobile clients will get db update?! I think this is with no revisions so?!
if you are using the Node.js smart client for Couchbase Server, you can still co-exist with Couchbase Lite mobile clients using a workflow we call "bucket shadowing". For more information on this, check out: https://github.com/couchbase/sync_gateway/wiki/Bucket-Shadowing
Alternatively, you could use a Node.js library that interfaces directly with the Sync Gateway instead. For example, cradle: https://github.com/flatiron/cradle
But, for most use cases, I would recommend the bucket shadowing method instead.
I've attempted to approach it from a similar direction in PHP.
Sync_gateway is based on CouchDB API but has some changes and missing features in it's architecture when compared to a normal Couchbase or CouchDB instance.
Sync/Admin REST API:
Attachments aren't supported: Sync_gateway runs in memory passing JSON documents to clients and isn't designed to store larger binary files.
Views aren't supported (except for a few special sync_gateway views): A sync_gateway pipes documents through channels to the authenticated users instance of Couchbase Lite. View design documents are passed also then ran on the client to analyse the documents they have locally. Structurally views otherwise have no ability to change their contents based on which user is authenticated, as they are pre-computed indexes.
Get/store docs, adding/removing users, channels, roles, DB compact, registering new databases as sync_gateway and a few other handy features are exposed.
So depending on your needs it is possible to connect a web-app to sync_gateway and retrieve documents, however "bucket shadowing" with separate ACL system for the web-app is likely the solution for most applications.
Alternatively you could compile Couchbase Lite for the server node and have the web-app connect to it, however this Couchbase Lite instance will only represent a single user and contain only their channel's documents.
PHP Client for Sync Gateway: https://github.com/mryellow/PHP-on-CouchSync/
Update: Nowadays probably the best way to go is with PouchDB for the web side. You can monitor changes with AngularJS and make responsive interfaces that will automatically react to your data changes in the browser.
I want to synchronise a local Android database with a remote database on a server somewhere. For now, I want to do this via a REST API with basic HTTP authentication.
I have done some reading and watched the Google I/O 2010 "Developing Android REST Client Applications" video, however I am still a little confused as to which approach will be most suitable for me:
1.) Content Provider + Service
2.) Content Provider + SyncAdapter
3.) Something else?
I have already written a Content Provider. I am a bit confused about the SyncAdapter and how authentication works - can I used basic HTTP authentication with a SyncAdapter?.
Authentication is done with accounts in Android. Have a look at this class: https://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html
Also have a look at this blog post:
http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
Regarding which approach to choose: If you want to sync between a remote DB and a local DB (that is you really want to sync and not only download content) a sync adapter is always the best choice!
If you have downloaded Android's samples you should also dig into the SampleSyncAdapter project. This should get you started.
BTW: Never ever do Basic HTTP authentication. This is not encrypted and all communication between your server and the app is readable to all. Always use TLS (SSL) instead!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to sync data (such as db record, media) between an Android App and a Server. If you've seen Evernote or similar Applications, you certainly understand what I mean.
I have some question (imagine we want to sync DB records):
Every user has a part of server space for himself (such as Evernote or Dropbox). Maybe the user creates new records by cellphone and creates new records in server. How can I match these records together? If there are records with same ID What algorithms do you suggest me?
Except JSON, Are there any way for send data between cellphone device and server?
If SyncAdapter and ContentProvider can solve my problems, please explain exactly for me. (If you could offer some samples or tutorials to me OR Any advice or keywords to help broaden/guide my search would be appreciated as well).
I'll try to answer all your questions by addressing the larger question: How can I sync data between a webserver and an android app?
Syncing data between your webserver and an android app requires a couple of different components on your android device.
Persistent Storage:
This is how your phone actually stores the data it receives from the webserver. One possible method for accomplishing this is writing your own custom ContentProvider backed by a Sqlite database. A decent tutorial for a content provider can be found here: http://thinkandroid.wordpress.com/2010/01/13/writing-your-own-contentprovider/
A ContentProvider defines a consistent interface to interact with your stored data. It could also allow other applications to interact with your data if you wanted. Behind your ContentProvider could be a Sqlite database, a Cache, or any arbitrary storage mechanism.
While I would certainly recommend using a ContentProvider with a Sqlite database you could use any java based storage mechanism you wanted.
Data Interchange Format:
This is the format you use to send the data between your webserver and your android app. The two most popular formats these days are XML and JSON. When choosing your format, you should think about what sort of serialization libraries are available. I know off-hand that there's a fantastic library for json serialization called gson: https://github.com/google/gson, although I'm sure similar libraries exist for XML.
Synchronization Service
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
As for how you identify if the records are the same, typically you'll create items with a unique id which you store both on the android device and the server. You can use that to make sure you're referring to the same reference. Furthermore, you can store column attributes like "updated_at" to make sure that you're always getting the freshest data, or you don't accidentally write over newly written data.
If we think about today, accepted answer is too old. As we know that we have many new libraries which can help you to make this types of application.
You should learn following topics that will helps you surely:
SyncAdapter: The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.
Realm: Realm is a mobile database: a replacement for SQLite & Core Data.
Retrofit Type-safe HTTP client for Android and Java by Square, Inc. Must Learn a-smart-way-to-use-retrofit
And your sync logic for database like: How to sync SQLite database on Android phone with MySQL database on server?
Best Luck to all new learner. :)
If you write this yourself these are some of the points to keep in mind
Proper authentication between the device and the Sync Server
A sync protocol between the device and the server. It will usually go in 3 phases, authentication, data exchange, status exchange (which operations worked and which failed)
Pick your payload format. I suggest SyncML based XML mixed with JSON based format to represent the actual data. So SyncML for the protocol, and JSON for the actual data being exchanged. Using JSON Array while manipulating the data is always preferred as it is easy to access data using JSON Array.
Keeping track of data changes on both client and server. You can maintain a changelog of ids that change and pick them up during a sync session. Also, clear the changelog as the objects are successfully synchronized. You can also use a boolean variable to confirm the synchronization status, i.e. last time of sync. It will be helpful for end users to identify the time when last sync is done.
Need to have a way to communicate from the server to the device to start a sync session as data changes on the server. You can use C2DM or write your own persistent tcp based communication. The tcp approach is a lot seamless
A way to replicate data changes across multiple devices
And last but not the least, a way to detect and handle conflicts
Hope this helps as a good starting point.
#Grantismo provides a great explanation on the overall. If you wish to know who people are actually doing this things i suggest you to take a look at how google did for the Google IO App of 2014 (it's always worth taking a deep look at the source code of these apps that they release. There's a lot to learn from there).
Here's a blog post about it: http://android-developers.blogspot.com.br/2014/09/conference-data-sync-gcm-google-io.html
Essentially, on the application side: GCM for signalling, Sync Adapter for data fetching and talking properly with Content Provider that will make things persistent (yeah, it isolates the DB from direct access from other parts of the app).
Also, if you wish to take a look at the 2015's code: https://github.com/google/iosched
For example, you want to sync table todoTable from MySql to Sqlite
First, create one column name version (type INT) in todoTable for both Sqlite and MySql
Second, create a table name database_version with one column name currentVersion(INT)
In MySql, when you add a new item to todoTable or update item, you must upgrade the version of this item by +1 and also upgrade the currentVersion
In Android, when you want to sync (by manual press sync button or a service run with period time):
You will send the request with the Sqlite currentVersion (currently it is 1) to server.
Then in server, you find what item in MySql have version value greater than Sqlite currentVersion(1) then response to Android (in this example the item 3 with version 2 will response to Android)
In SQLite, you will add or update new item to todoTable and upgrade the currentVersion
Look at parseplatform.org.
it's opensource project.
(As well as you can go for commercial package available at back4app.com.)
It is a very straight forward and user friendly server side database service that gives a great android client side API
one way to accomplish this to have a server side application that waits for the data. The data can be sent using HttpRequest objects in Java or you can write your own TCP/IP data transfer utility. Data can be sent using JSON format or any other format that you think is suitable. Also data can be encrypted before sending to server if it contains sensitive information. All Server application have to do is just wait for HttpRequests to come in and parse the data and store it anywhere you want.
I would suggest using a binary webservice protocol similar to Hessian. It works very well and they do have a android implementation. It might be a little heavy but depends on the application you are building. Hope this helps.
#Grantismo gives a great overview of Android sync components.
SyncManagerAndroid library provides a simple 2-way sync implementation to plug into the Android Sync framework (AbstractThreadedSyncAdapter.OnPerformSync).
https://github.com/sschendel/SyncManagerAndroid
I'm developing a android application for a customer which involves capturing data on the handset and then synchronizing it later to a server. They want me to use Funambol server and client to sync data. I have tried looking up on the www.funambol.com website for any api and documentation, but am not able to find any library for android.
Has anyone done any similar work using funambol? I need to sync a list of customers and their related data which will be entered by a salesman.
Thanks
Funambol has a syncml api for android that is used in the Android client, and can be used for performing the sync without the need of implementing syncml. You will only need to work on client and server side to implement the proper syncsource for your specific data, and store the data on both sides.
Take a look at https://www.forge.funambol.org/download/ (bottom of the page)
The developer community can be reached at bit.ly/fun-open-discuss, where you can discuss development topics and share your project and code (as required by AGPL).
Funambol provides open source-based solutions for push email & PIM sync as well as device management and a platform for mobilizing apps and data. Funambol is based on the SyncML (OMA DS) standard for data synchronization.
Read the FAQ