How to Export/Import Data from the local database? - android

I am working on an iOS and Android app which uses a local database for saving the data. Now my client wants to add the export & import data option in the app. So that the user can export data from one device and import it on any other device to use his account as it is. How can I do that? Any references or help.
Thanks In Advance!!!

You can try to export all the data from the database to a .csv file and read from iOS or viceversa.
You can find an example of how to export data in Android here

The best way to do that is creating a way to read data and write data to a .csv file. In reading you can easily write your data like a text file and separate every entry with ','. and reading data from it is also easy , you can read file line by line and use java string tools to process the string file and fetch data from it.
Beside it can be edited or generated by Microsoft excel. So the client could easily work with it.

Related

How do I access a text file from GCP Storage and parse it?

I have an app I want to make for Android. I have decided to store the information I will display in a text file and parse it, rather than a database since the data is so simple.
The info is just two lines of text, a word and a short description of that word. I want the app to get each pair (word, description) from the text file and display it on a card in the app.
I stored the .txt file in Google Cloud Platform Storage and now I need help writing the code to access the file(s) and parse them to use in a Cards UI.
I can find no helpful examples of how to get this file then parse it in the app in a smooth way.
You can use a client library to open the file and read it. For example, the Python client library is at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions
and your code would look like this:
import cloudstorage
try:
gcs_file = cloudstorage.open(filename, 'r', content_type='text/plain')
# process as normal ...
except cloudstorage.NotFoundError:
pass
Sample Java client code is at https://cloud.google.com/storage/docs/xml-api-java-samples

SQLite database file upload at server in SQL format

I want to upload local sqlite database file at server but in sql format. Is it possible to directly save it in mysql supported format? The file is uploaded successfully on server but its just a flat file of sqlite db. When i open it in editplus or import it in phpmyadmin, it shows error. But when I manually export the database from sqlite manager in .sql extension, it successfully gets open in readable format in editplus. Please help me with this problem. Thanks in advance !
AFAIK you are talking about two completely different things.
Its like comparing a DB dump file to a properly exported file like an xml file with schema and data information from Oracle or MySql
When you export you get a file with or without .sql extension and it means a file with set of queries like DDL or DML create,insert etc. That may be sequentially run to execute all the commands in it and provide you with the right schema and data present in that file.
Whereas a DB file that is created via app is specific to the device and is an .sqlite file which is specific to sqlite browser and that may read it and not a set of queries only that you may open in edit-plus or a text editor.
Sqlite DB file that you find on your device is dynamically generated pages to maintain the integrity of the db.
For more info you must read,
Format of sqlite database
Sorry I don't have code but the idea is,
--Edit with algo--
Assuming you have the create commands for all tables and constraints with you , as they are not going to change most of the time.
You may use this function as a Utility to create and maintain the sql
command list for you parallel to the db you have.
void createExportCommands()
{
...
- Read all tables one by one using a `Cursor`
- Based on specific tables/columns create queries
i.e. String query="insert into "+your_table+" values("+cursor.getString(0),....+");";
- Write this data into a file called export_data.sql and keep updating it in background
}
Perhaps its not the best approach but it will solve your issue.

How to export/import data on Android

I have an application that stores data in SQLite db. I've implemented export of this data to external file (in json format) with custom file extension. Also I have an activity that starts when user opens my file and saves it back to SQLite.
I don't want to backup my db, I'm exporting a part of data to be used by another users.
My next goal is to make sharing this data via Bluetooth (export it to Dropbox / send via email). I want it to look like described in this tutorial: http://developer.android.com/training/sharing/send.html but I doubt that this tutorial is what I need.
I don't want users to export data to file and then send this file via Bluetooth, I want them to share data directly from my app.
I looked at FileProvider. I'm confused with insert, update and other methods so I'm not sure this is the right choise.
I looked at Sending Binary Content tutorial but I don't know how to create intent properly and how to save my temporary file for sharing.
Please, describe the way to share this type of data or give me links to examples. Thanks!
P.S. sorry for my English

Android: Export part of my SQLlite table to a file and upload it to the Database of the same app on a differnet phone

I am trying to figure out how to export a specific part of my Database to a file and then send the file to a friend to open it on his phone and to automatically insert the values from that file into his Database in the same application.
So the idea is to be able to share a specific part of my Database. That way I will be able to have the option to send the file through messaging, e-mailing, etc.... . That will also give me the opportutnity to backup the user data upon user request. I have no idea what I need and how can I do that. Thanks!
You can do it like:
Step1:
Load the data you want to share.
Step2:
Convert it to SQL queries.
Step3:
Send it to other device using web service.
Step4:
Run the SQL queries on other device.

Android log in and download csv file

I am writing an Android app and I need to download a csv file for a graph. I am not sure if I need to either put the two columns to two array strings or import them to the DB then just query. I am leaning towards just putting them to strings since the csv file will change constantly.
My two issues are:
I need to log into a specific URL to populate the CSV with the correct data such as http://myurl.net/protect/module_graph.htm?log=02. That will populate the file http://myurl.net/protect/data1.csv with the data for the correct item. Changing the log=02 to log=03 or any other number changes the content of the data1.csv file. When I pull up the first URL in a web browser it pops up a window asking for basic authentication. How do I need to call the URL to send the username and password with the request?
I need to get the CSV file downloaded and have the two columns output as strings so the graphing code can just read the data from the strings. I think I know how to download it but should I store it to the SD card and then output the data or just open the file from the web and then output the data? Also how do you tell it to put each column to an arraystring?
Any help is appreciated. Code examples or links to tutorials or other options are much much appreciated :)
Thanks!
You never say it, but I assume you are developing an Android app:
Use HttpClient GET with authentication: an example.
Again use HttpClient GET and look at the reply.

Categories

Resources