Android log in and download csv file - android

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.

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

how to manage data for view immediately after database file is imported into web application?

My title might have explained you a lot. But still I explain you in a use case way. In my web I have a database file that I insert data using form. I know, it is possible to see the data easily. After that, I export the same database file into my work station and then from there I import the file to android application. That database file is used for CRUD operations. When everything is done the same file is again imported to the web app and merge the two database files (web app database file and android database file) to be one and manage for the views of data.
Now, the question is that am I able to see the data from that merged file immediately after I import. When I import database file to web app, two files merge to one and then only data can be viewd. I can merge the two database files by coding but for the view is the system responsible? Or, how can I do it fast? I mean I import file and after that I want to see changes of data in my view of web app.
I hope some one lead me to right direction. Only logical answer is required. Please do not suggest me another way to do because this is the only one way I want to do. Thanks in advance :)!!
I hope Server-sent events will be more opt in your criteria. (ie) Whenever you have a database update in your server side (using code or any), you need to trigger a "Server-sent event" so that it will be sent to your clients and make them request for view update or directly update through the trigger message.
Please check this QA for more clarification.
Server-sent events

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

Storing a large amount of backend data in Android

I am developing a places of interest app which will display the list of places of interest in a location.
When user chooses one, it will display more information and address etc.
How do I store all this data? Currently I am using a text file to store all the data and subsequently when user chooses a place, it will parse the text file and retrieve the necessary data for display.
Any advice on what is a better way to do this? I looked at SharedPrefs, but it is more like storing "key-value" pair and in this case I need to store a large amount of data.
I want the info to be available even when the device is offline, thus I can't download from an online server upon request.
Any other way to do this?
You may store it to XML file using XML serializer, here is very good tutorial for learning that,
http://www.ibm.com/developerworks/library/x-android/
and it can be easily parsed using Java XPath Api. Have a look at this at parsing XML files
http://www.ibm.com/developerworks/library/x-javaxpathapi/
Use SQLite
It can store large data.
It is available offline.
All your problems will be sorted out.
Hre we have a wonderful tutorial for sq-lite
http://www.vogella.com/articles/AndroidSQLite/article.html
How about a relational database?
http://developer.android.com/training/basics/data-storage/databases.html
Take a look at Serialization. If you do not need database access, you could define a class what holds every information you need. Then, you can do the following:
when you need to save the datas, you serialize your object, dumping its content to a file, for example on the SD card
when you want to load the datas, you just load the above mentioned file, and get back everything from the dumped file
I am using this method in my app to cache some datas that would need internet access, so the user can still view it, and with proper implementation, this can work very nicely.
Use database, create table and insert all the data in it. When you need the data just fire the query, and you are done.
SQLite is fine for Android.
Depending on the type of data you want to store, you could use a SQLite Database (provided with Android) if it has a normal database structure. You could Serialize your data and save it in a raw or encrypted file, making you data implement Serializable.

How to write the text file after received the location?

I'm implementing the application just like tracking the user's traveling.
Now I'm using the SQLite database which is record the location, time,and date
then automatically send to the MySQL server via JSON if the Internet is connecting.
But I want to do like the following:
1) I would like to keep data as a text file of each traveling before send to server.
2) I don't know that I should record data in SQLite before write as a file or not?
3) I also need to list all files in the document menu to show user all files
and check the status of all files are completely sent or did not send.
I tried to search for the good tutorial and any examples but did not find them yet.
If anyone have a good tutorial for write/read file and any idea for these, please suggests me.
Thank you so much
Here is good tutorial how to write data to file and save it to SD card.

Categories

Resources