简体   繁体   中英

Android Google Drive SDK: Saving to App Folder

For my current project, I would like to allow a user to create a sqlite database file and have them enter some content. Then the user has the option to sign into their google drive account and upload this file. Afterwards, after the user makes further edits, the new database file is uploaded to replace the old file. Finally, if the user has multiple devices, the database should be downloaded from the google drive and replace the existing file stored on the device.

Currently, I have successfully setup Google Drive SDK authentication and I can sign in to the app with my account.

My main question is, how do I upload a sqlite database file to the APP FOLDER when I choose to press a sync button? (This method should be called when the user needs to sync)

Additionally, how do I upload a sqlite database file to the APP FOLDER?

Your question is a bit broad, but I'll try to send you in the right direction.

First you have to decide if to use the REST Api or GDAA . Both will accomplish the same (actually the GDAA's functionality is a bit narrower now, but for your situation will do). The big difference is that GDAA will handle on-line / off-line states for you, where with the REST Api, you have to implement some kind of non-UI thread (sync service) synchronization. Also, there are latency issues you must be aware when using GDAA.

Next, the process of uploading SQLite database is the same as any other binary data stream.

  • Grab the 'xxx.db' file, make output stream (or byte[] buffer) and create a GooDrive file with title + mimetype metadata, push the stream into it's content and send it on it's merry way. The only difference between a standard folder and an app folder is the parent of the file.

  • You get an ID you can subsequently use to download the file to the device. Or you can use search by metadata (title in your case) to get this ID. Again it comes as input stream and you dump it to an 'xxx.db' file on your device.

The second portion of your question deals with multiple devices. None of the apis will notify you about a change in GooDrive, so you must implement one of the 2 strategies:

1/ Polling (ouch), preferably in sync service with sync intervals the system gives you.

2/ GCM message broadcasted to the devices / users who are interested (not trivial, but efficient ... and sexy).

Another pitfall you must be aware when using multiple devices with GDAA is described in SO 29030110 and SO 22874657 .

In case you decide to play with the 2 apis, I maintain basic CRUD implementation demos for both the REST and GDAA . The GDAADemo has also an option to work with the app folder.

Good Luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM