Android - Google Drive REST API - Adding a row to a CSV file - android

This question concerns adding a new row to a CSV file that exists in Google Drive using the Google Drive REST API.
On my Android device, I have a CSV file that I am building locally. If I add a row to the local CSV, I want to also add that row to the CSV that resides on Google Drive.
I've got the fileId of the CSV, and I can PUT the file to do a direct replacement, but I'm trying to save bandwidth as the file size grows.
I have been looking into JSON Patch as the transport to perform this, but I cannot find a concrete example after looking for days. For instance, how does JSON Patch write to the CSV file? Is the "path:" parameter the column header? Is a "op", "add" needed for each column?
I just need to pointed in the right direction.

To my best knowledge, it is not possible. You are trying to append (modify) the content of a file and the only way I know of in both the REST Api and the GDAA is to get the content, modify it and upload. It is possible that GDAA may (one day) internally do some diff / incremental optimization, but I doubt it.
My rational for this guess is that the content is being shipped as base64-ed, gzip-ed, ... binary stream with no embedded knowledge of the mime type, so the 'append' functionality would get quite complex.
The PATCH functionality you'r looking into deals only with METADATA (title, mime, modi-dates, parentIDs, etc...). See the fields available in Try it! on the bottom of this page.
Good Luck

In case anyone else comes across this question, an alternative solution (which doesn't involve switching to using a Google Sheets file) would be to move the read-modify-write API calls to a small service hosted on Google Apps Script and call that service from your application using the recently-announced Execution API.
You would call the hosted script with the new row to be appended to the file, and the script (running in the cloud and with very fast access to the Drive API) would get the file content, append the new row, and then save the file back to Drive. This would save bandwidth between your mobile application and the hosted script.

Related

How to update an excel sheet from Android App

I am trying to establish a simple method for retrieving reference-information from a few cells of an existing excel spreadsheet from an Android app (which is located on a secure company network drive - but could be moved to a secure cloud). Then I wish to add information to that "record" or row of the same spreadsheet.
Is a SQLite database required to do this? or can I pull the reference info directly from the existing excel sheet into a table/list in the app, and then choose to add info to the same sheet in cells relative to the selected reference info/record?
I have looked through the forum and the web and found lots of info on SQLite but nothing that quite fits my requirements.
The idea of this is to be able to find and select a record on the app and then add details (inc. photo's) to that record. So updating the excel sheet with the additional information.
The existing sheet is populated with reference information on a PC and saved to the network drive, to be later added to via the android app as above.
Any help and guidance is much appreciated.
There are two different versions of Excel Sheet file formats used today.
Is the old fashion OLE based file ending: xls
Is the new style XML based file ending: xlsx
Both of them can be processed by java and also on android.
Best practice to work with office docs in Java is the Apache POI project, which can handle both kinds of office formats.
Her is the link to Apache POI for Excel:
http://poi.apache.org/spreadsheet/index.html
What you can do:
If it is OLE based your only choice is to use POI. But POI will always load the hole file into RAM which can be a problem on Android Deviecs with less RAM.
If it is XML based you can directly manipulate the data on the sheet in xml. The file format xlsx or any office doc ending on "x" is a zip file including XML Data and alot of meta informations etc. A file of this kind can be decompressed in a temp folder, you can than read the xml data and manipulate them. After this compress the temp folder into a xlsx file and you are fine.
Or you can also use poi to work with the xlsx file, but also here it loads always the hole file. (I have running applications which push several thousand of rows in excelsheet using the xml technic)
Hope that helps.
P.S. I never tried to use Apache POI on Android, should work but I am not sure. Search on google for examples.
Here are some links regarding XML and Zip technic:
ZipFile in Android SDK: http://developer.android.com/reference/java/util/zip/ZipFile.html
Offical XML Android Docs: http://developer.android.com/training/basics/network-ops/xml.html
Good tutorial about xml parsing using library XMLPullParser: http://developer.android.com/training/basics/network-ops/xml.html
Official XLSX Specs from Microsoft: https://msdn.microsoft.com/en-us/library/dd922181%28v=office.12%29.aspx
Exmple for big Sheets directly manipulating the xml data: https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java

Android App to talk to a web server, download a file and parse

I am new to this. I have the Android SDK installed with Eclipse. I can work with basic activities and layouts.
I am looking to write this Android application that will;
1) Allow users to sign-in using a pre-allocated password.
2) Login and change the password.
3) Every time the user opens the app, he downloads a CSV file from a server to the SD card.
4) The app parses from the file and displays them on several activities and small frames inside the app.
Think of it as an informational application. But, I'd like to add some intelligence on top of it after I get this done.
I have read many articles and topics but none of them give me a specific approach to do this faster. I have very little time for development.
If there's a similar application that you're familiar with, I'd like to take a look at the code.
I want to know exactly (the code) on how the communication between the app and a linux based server on the web needs to be established. Right now, there's only a CSV file (or an EXCEL file - which one's better to parse? How to decide?) there.
Also, when the CSV file is up to date, I wouldn't want it to download the file again. How to prevent it?
As I said, I am new - so please be patient.
Thanks
If you are new to this and want to develop something fast, why do it the hardest way, in java? There are so many easy toolkits out there, e.g. RFO.Basic, you will be amazed how much you can achieve, fast, that way.
(You asked several questions) Easiest to parse? If you don't have Excel installed on your Android device, the CSV is of course easier to parse, needing only text tools. However, if you have a choice of formats, why not use XML? If you have never worked with XML, there is a little learning curve, but there are lots of tutorials on the web. After that, you'll never want to go back to CSV.
Your last question: how to prevent download of unchanged file? Is this about a big file? In that case start with quickly downloading the hash (checksum) of the file, so that the client can decide if the file has changed.

Using an online .txt file as a data source

I am building an Android app for a client and most of the data that i need is contained in an online .txt file attached to my clients website. I've never used an online .txt file as a data source before and don't really know where to begin?! Can anyone point me in the direction of a good tutorial on the subject.
Many Thanks in advance
P.S. I haven't asked whether it's possible because i have assumed it is due to the fact you can use an internal .txt file as a data source
I think the best approach is to download the file on the device and then read it like a normal file. If the file changes on a period of time, then configure the app to download and read the file and then update the local info in the app.
I don't think you can use an online txt as a DataSource, but you can implement this so you have an abstract source for your file, and then just call read on it.
Expose the txt/xml file over web,if you want to get it down to phone use URL loader and load it to the phone and operate if you want to use it online (like others may also be using it) it will be a bit complex in order to deal with data coming from more then one source but possible. clear you question a bit more.

how to download PDF file from server.

I am trying to download a file from server, what I have in mind to get filename in json response and the content and write same in assets or on sdcard. should i go and implement same, or there can be some other way we can achieve the same.
Actually you know you control the way you expose the content from the server - you can just make the file itself (its bytes) exposed at certain url. If you need to keep the name of the file posting as json seems to be good solution.
However, there is one trick here: I don't know how big the file you refer to is and also how reliable the network will be. For every bigger file I will recommend to implement resumable upload via byte serving. You can read about the byte serving client consumer in Android in this thread. Then just go and see on how to implement byte serving server side - it definitely depends on the platform in the only case in which I used such mechanism I actually had to mimic the byte-serving with my custom url parameter. If you need further help on server side write back and I will extend my answer.

Does an Android ContentProvider exist for storing and providing Google Transit Feed data?

I am writing an Android app for my local transit authority. They publish their data in the the Google Transit Feed Specification (GTFS). I'd need to download this feed and save it to the device and allow my application to access the contents. Since the feed data has a standard specification, I figured I'd store behind a general ContentProvider serving general GTFS type data, that I could then access in a standard way.
I figure, this is a Google standard, I can't be the first to want to store and provide GTFS data on an Android phone; why reinvent the wheel, right? But, I haven't been able to find any such ContentProvider.
Does anyone know if there is an Android ContentProvider, or something similar, for storing and providing GTFS data? If not, I'll write my own; if I have to write code to store and provide transit data, I may as well make it standard; but since I'm still very much green to Android programing, I'd prefer to use a more professionally written ContentProvider, if one exists.
Use protocol binary format (pbf) formely google and now open source. It is compact and very fast searchable, so no need to decompress it on a device and load it into a database on that device because pbf acts as a database. Just include pbf library in your code to query it. Of course you have to compress it once before distributing the data online. Once downloaded you can use the dats in pbf offline

Categories

Resources